I've created a multi auth test in Laravel 5.4. It's using custom middlewares, custom Eloquent providers, etc. The auth flow is working, I can login in both ways. But if the user is signed in, in the home controller when I want to check the user with Auth::user() or Auth::guard()->user(), it's empty. The Auth::guard() is empty as well. But I don't understand, why?! It should contains the signed in user instance, shouldn't it?
Also the $request->getUserResolver() says that the guard is null... o.O
What did I do wrong?
Here it is my test repo, if you want to check my code.
Thank you in advance!
Edit 1:
In the \app\Http\Controllers\Employee\HomeController.php the Auth::guard()->user() and the Auth::user() are empty.
namespace App\Http\Controllers\Employee;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class HomeController extends Controller
{
public function __construct(Request $request)
{
$this->middleware('auth.employee:employee');
}
public function index(Request $request)
{
$users[] = Auth::user();
$users[] = Auth::guard()->user();
$users[] = Auth::guard('employee')->user();
dd($users);
return view('employees.home.index');
}
}
Auth::guard('employees')->user();And before jumping into that you have to make sure that your guard is reach outloginmethod inside theIlluminate\Auth\SessionGuardclass to populate the session. What I mean was how'd you authenticate the user at the first place?Auth::provider('eloquent.employee' ...)you filled out with the driver name which should beAuth::provider('employees' ...)And, doesn't it need to be loaded just beforeAuthServiceProviderresolved, like registering the provider insideAppServiceProviderinstead? Dunno...