diff --git a/app/Http/Middleware/AdminAuth.php b/app/Http/Middleware/AdminAuth.php new file mode 100644 index 0000000..b75200e --- /dev/null +++ b/app/Http/Middleware/AdminAuth.php @@ -0,0 +1,20 @@ +check()) { + return redirect()->route('admin.login'); + } + + return $next($request); + } +} diff --git a/app/Http/Requests/Admins/AdminPostRequest.php b/app/Http/Requests/Admins/AdminPostRequest.php new file mode 100644 index 0000000..2f5571f --- /dev/null +++ b/app/Http/Requests/Admins/AdminPostRequest.php @@ -0,0 +1,42 @@ +|string> + */ + public function rules(): array + { + return [ + 'email' => [ + 'required', + 'email', + 'min:10', + 'max:150', + + ], + + 'password' => [ + 'required', + 'string', + 'min:2', + 'alpha_num', + ] + ]; + } +} diff --git a/app/Models/Admin.php b/app/Models/Admin.php new file mode 100644 index 0000000..d8d0c14 --- /dev/null +++ b/app/Models/Admin.php @@ -0,0 +1,43 @@ +withMiddleware(function (Middleware $middleware) { $middleware->redirectGuestsTo(fn(Request $request)=>route('auth.login.index')); + $middleware->alias([ + 'admin.auth' => AdminAuth::class, + ]); }) ->withExceptions(function (Exceptions $exceptions) { diff --git a/config/auth.php b/config/auth.php index 0ba5d5d..f3895c0 100644 --- a/config/auth.php +++ b/config/auth.php @@ -40,6 +40,10 @@ return [ 'driver' => 'session', 'provider' => 'users', ], + 'admin' => [ + 'driver' => 'session', + 'provider' => 'admins', + ], ], /* @@ -64,6 +68,10 @@ return [ 'driver' => 'eloquent', 'model' => env('AUTH_MODEL', App\Models\User::class), ], + 'admins' => [ + 'driver' => 'eloquent', + 'model' => App\Models\Admin::class, + ], // 'users' => [ // 'driver' => 'database', diff --git a/routes/admins.php b/routes/admins.php new file mode 100644 index 0000000..b691b54 --- /dev/null +++ b/routes/admins.php @@ -0,0 +1,20 @@ +controller(LoginController::class) + ->name('admin.') + ->group(function () { + + Route::get('login', 'index')->name('login'); + Route::post('login', 'login')->name('login.post'); + Route::post('logout', 'logout')->name('logout'); + + Route::middleware('admin.auth')->group(function () { + Route::get('dashboard', [DashboardController::class, 'index'])->name('dashboard'); + }); + + }); diff --git a/routes/auth.php b/routes/auth.php index 0430f35..46aef78 100644 --- a/routes/auth.php +++ b/routes/auth.php @@ -1,6 +1,6 @@