<?php

namespace App\Http\Controllers;

use App\Models\User;

class ReferralRedirectController extends Controller
{
    public function __invoke(string $code)
    {
        $referrer = User::where('referral_code', $code)->first();

        if ($referrer) {
            session(['referral_code' => $referrer->referralCode()]);
        }

        return redirect()->route('register');
    }
}
