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');
}
}