thanks @ismaile
im sorry for late
my auth.php // i add admin guards and providers
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
'hash' => false,
],
'admin' => [
'driver' => 'session',
'provider' => 'admin',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
'admin' => [
'driver' => 'eloquent',
'model' => App\Models\Admins::class,
],
in redirectifauthenticated.php
public function handle($request, Closure $next, ...$guards)
{
$guards = empty($guards) ? [null] : $guards;
if (Auth::guard($guards)->check()) {
if($guards == 'admin')
return redirect(RouteServiceProvider::ADMIN);
else
return redirect(RouteServiceProvider::HOME);
}
return $next($request);
}
in routeserviceprovider.php
public const HOME = '/home';
public const ADMIN = '/admin/dashboard';
protected $namespace='App\Http\Controllers';
public function boot()
{
$this->configureRateLimiting();
$this->routes(function () {
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web.php'));
Route::middleware('admin')
->namespace($this->namespace)
->group(base_path('routes/admin.php'));
Route::prefix('api')
->namespace($this->namespace)
->middleware('api')
->group(base_path('routes/api.php'));
});
}
admin.php //new route file
Route::group(['prefix'=>'admin','middleware'=>'guest:admin','namespace'=>'Admin'],function(){
Route::get('/login','LoginController@getAdminPage')->name('admin.login');
Route::post('/login','LoginController@login')->name('admin.login');
});
new error
ErrorException
Illegal offset type