routing - Using middleware in Laravel 5.3 -


i'm attempting create middleware in laravel 5.3 checks see if user admin can restrict routes admins only.

my middleware:

<?php  namespace app\http\middleware;  use closure;  class isadmin { /**  * handle incoming request.  *  * @param  \illuminate\http\request  $request  * @param  \closure  $next  * @return mixed  */     public function handle($request, closure $next)     {         if( !\auth::user()->hasrole('admin') ) {             return redirect('login');         }          return $next($request);     } } 

i register in kernal, adding ti protected below:

protected $routemiddleware = [      ....      'isadmin' => app\http\middleware\isadmin::class, ] 

then try secure route with:

route::resource('user', 'usercontroller')->middleware('isadmin'); 

but error route file:

fatalthrowableerror in web.php line 103: call member function middleware() on null 

you should apply middleware ::group():

route::group(['middleware' => 'isadmin'], function () {     route::resource('user', 'usercontroller'); }); 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -