jeudi 14 septembre 2017

laravel 5.1 auth login returns an error

I'm trying to use auth()->login() in laravel 5.1 but it returns an error. Please see my code below:

$user = User::where('username', $username)->where('activation_code', $activation_code);
$not_activated_user = $user->where('status', 0)->where('confirmed', 0);

if($not_activated_user->count() == 1){
    $not_activated_user->update([
        'status' => 1,
        'confirmed' => 1
    ]);

    auth()->login($user->where('status', 1)->where('confirmed', 1));
}

I've also import use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; and implements AuthenticatableContract in my User model, but it still returns the same error. Why is that? I also tried to use ->get() in ->login(....->get()) to get the current user, but still same error.

Error:

Argument 1 passed to Illuminate\Auth\Guard::login() must implement interface Illuminate\Contracts\Auth\Authenticatable, instance of Illuminate\Database\Eloquent\Builder given



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire