i want to view dashboard when logged in as both "admin" and "jeweller". When i log in a "admin" its redirecting to dashboard, when when i log in as jeweller, its not going to dashboard. I have 2 types of admin & tables ie.. "admin", "jeweller"
In auth.php , i have created 2 types of providers
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'admin' => [
'driver' => 'session',
'provider' => 'admins',
],
'jeweler' => [
'driver' => 'session',
'provider' => 'jewelers',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
'admins' => [
'driver' => 'eloquent',
'model' => App\Admin::class,
],
'jewelers' => [
'driver' => 'eloquent',
'model' => App\Jeweler::class,
],
],
i have declared a middleware called "AdminAuthenticated" , in AdminAuthenticated.php we have
class AdminAuthenticated
{
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
return $next($request);
}
return redirect()->route('admin.login');
}
}
and in web.php we have
Route::group(['prefix' => 'admin','middleware'=>
['adminAuth:admin','adminAuth:jeweler']], function () {
});
and in kernal we have
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
// \Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
'api' => [
'throttle:60,1',
'bindings',
],
];
protected $routeMiddleware = [
'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'adminAuth' => \App\Http\Middleware\AdminAuthenticated::class,
];
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire