Your perfect administ on Laravel.
-
I decided not to use the ready, but to make the perfect adminc on the laravel project.
And at the beginning, there's a question. One day on the routes/routes, indicate that the way
/admin
It's only for "selected," so he wouldn't let the usual lasers go there and all of him?I still have one idea: in every method of every adminica class, a condition for checking the status of a laser is But it's a bad code.
If the routs don't sign this, at least give me the best solution.
-
For starters, create middleware admin
php artisan make:middleware admin
Then add this code to the model user.
// is admin public function isAdmin() { return $this->is_admin; // поле is_admin в таблице users }
Open the middleware admin and add the code.
// проверяем принадлежность пользователя if ( Auth::check() && Auth::user()->isAdmin()==true ) { return $next($request); } return redirect('/');
App\Htp\Kernel.php in protected $routeMiddleware add our middleware
'admin'=>\App\Http\Middleware\admin::class,
and finally in the route
Route::group( [ 'middleware' => 'admin', 'prefix' => 'admin' ], function () { // только для админа });