I have a Laravel Application using Multi User tables for different roles.
I have added 2 custom guards like this:
'guards' => [
'consumer' => [
'driver' => 'session',
'provider' => 'consumer',
],
'member' => [
'driver' => 'session',
'provider' => 'member',
]
]
And I want to share the the same route with both of consumer and member. But I dont know how Laravel pass guard name to the Auth middleware.
Look at file Illuminate\Auth\Middleware\Authenticate
protected function authenticate(array $guards)
{
if (empty($guards)) {
return $this->auth->authenticate();
}
foreach ($guards as $guard) {
if ($this->auth->guard($guard)->check()) {
return $this->auth->shouldUse($guard);
}
}
throw new AuthenticationException('Unauthenticated.', $guards);
}
If I can pass 2 custom guards to the $guards variable, It can share the route between custom and user. But I dont know how to pass the guard's name
you can just pass the guards with comma, for exapmle:
Route::group(['middleware' => ['auth:comsumer, member'] ], function(){
Route::get('/home', 'HomeController@index');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With