In app/Http/Authenticate.php added such code

 public function handle($request, Closure $next) { if ($request->user()->hasRole('admin') { return $next($request); } else if ($request->user()->hasRole('user')) { return redirect('404'); } else return redirect('/'); } 

A user with the user role when trying to access /admin receives 404, but, for example, /admin/articles - opens

upd: can I add a prefix to one of the groups?

 //admin routes Route::auth(); Route::group([префикс сюда,'middleware' => ['auth']], function () { Route::group([или сюда,'middleware' => ['role']], function () { 

    1 answer 1

    1) I would advise you to use the entrust package .

    2) You need to combine routes into a group with the admin prefix, and put middleware on it, in case of entrust it looks like this:

     Route::group(['prefix' => 'admin', 'middleware' => ['role:admin']], function() { //тут твои пути остальные }); 

    3) Even if you will not use the package, you need to create middleware and hang it in a group

    • I understand that the package is designed to create roles from scratch, some roles on the project were created without the use of packages. Can I create an add. role, using the package, but that already existing did not crumble? - Tarasovych
    • @Tarasovych depending on how to implement it :) everything depends on you, write some function as a container that will choose which test method to use, you can also change the middleware - Orange_shadow
    • Can I add multiple prefixes to a group? - Tarasovych
    • I added a little question, is there any point in adding a prefix for specific roles in the admin path? - Tarasovych
    • @Tarasovych you can ask the masses in the middleware, I don’t understand why doing so auth is actually part of the role, plus you can write it like this: admin | user | manager - Orange_shadow