Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

zxywvu's avatar

Illuminate\Auth\SessionGuard::login(): Argument #1 ($user) must be of type Illuminate\Contracts\Auth\Authenticatable, null given,

I have a mobile form

<form method="POST" action="{{ route('register') }}">
    @csrf
    <div class="row mb-3">
        <label for="mobile" class="col-md-4 col-form-label text-md-end">{{ __('mobile') }}</label>
        <div class="col-md-6">
            <input id="mobile" type="text" class="form-control @error('mobile') is-invalid @enderror" name="mobile" value="{{ old('mobile') }}" autocomplete="mobile">
            @error('mobile')
            <span class="invalid-feedback" role="alert">
                <strong>{{ $message }}</strong>
            </span>
            @enderror
        </div>
    </div>
    <div class="row mb-0">
        <div class="col-md-6 offset-md-4">
            <button type="submit" class="btn btn-primary">
                {{ __('register') }}
            </button>
        </div>
    </div>
</form>

RegisterController

protected function validator(array $data)
{
    return Validator::make($data, [
        'mobile' => ['required', 'numeric', 'digits:11'],
    ]);
}

protected function create(array $data)
{
    session()->remove('mobile');
    $code = rand(1000,9999);
    session()->put('mobile',$data['mobile']);
    User::query()->create([
        'mobile' => $data['mobile'],
        'code' => $code,
    ]);
}

I get this error

Illuminate\Auth\SessionGuard::login(): Argument #1 ($user) must be of type Illuminate\Contracts\Auth\Authenticatable, null given,

0 likes
8 replies
zxywvu's avatar

@Sinnbeck

I want to redirect to the sms page. but I see this error

Illuminate\Auth\SessionGuard::login(): Argument #1 ($user) must be of type Illuminate\Contracts\Auth\Authenticatable, Illuminate\Http\RedirectResponse given, called in C:\xampp\htdocs\projects\tehran\cyber-security\vendor\laravel\ui\auth-backend\RegistersUsers.php on line 36

protected function create(array $data)
{
    session()->remove('mobile');
    $code = rand(1000,9999);
    session()->put('mobile',$data['mobile']);
    User::query()->create([
        'mobile' => $data['mobile'],
        'code' => $code,
    ]);
    return redirect()->route('sms');
}
Sinnbeck's avatar

My best guess is that you need to return the user

protected function create(array $data)
{
    session()->remove('mobile');
    $code = rand(1000,9999);
    session()->put('mobile',$data['mobile']);
   return  User::query()->create([
        'mobile' => $data['mobile'],
        'code' => $code,
    ]);
}
zxywvu's avatar

@Sinnbeck

No after entering a mobile number by the user, I want to redirect the code with ajax.

Sinnbeck's avatar

@azadi So that does not fix the error? FIrst fix the error, and then work on what you want.

Please or to participate in this conversation.