mercredi 17 juillet 2019

Why login session data return NULL after successful login attempt in laravel?

I'm creating custom login for user owners. So in Owner\Logincontroller I put this code:

public function login(Request $request)
{
  $email = $request->email;
  $password = $request->password;

  if (Auth::guard('owner')->attempt(['email' => $email,'password' => $password],$request->remember)){
     return redirect()->intended('/owner/dashboard');
  }

  return redirect('/owner')->with('error','Login failed.');
}

At this stage, I check if Auth::guard('owner') has value and it does. But after redirected to url /owner/dashboard which is routed to Owner\HomeController@dashboard the Auth::guard('owner') has NULL value. I checked it using var_dump.

<?php
namespace App\Http\Controllers\Owner;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\Controller;
use App\Http\Middleware\Owner;

class HomeController extends Controller
{
   public function dashboard(){
     var_dump(Auth::guard('owner')->user());
   }
}

I put everything needed to make it work like configuring Kernel.php, auth.php. So I have no idea why the owner guard has NULL.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire