title: Laravrl5- user permissions for whole module controllers
body: <p>I created a simple system to set permissions for users in the admin panel using AdminMiddleware.
  Every user has permissions like groups, posts, pages ....</p>
  
  <p>Routes/web:</p>
  
  <pre><code>Route::group(['middleware' =&gt; 'admin'], function()
  {
      Route::get('/admin' , 'admin\AdminController@index')-&gt;name('admin');
    //all admin panel routes
  }
  </code></pre>
  
  <p>In the AdminMiddleware</p>
  
  <pre><code>public function handle($request, Closure $next)
  {
      if(Auth::check()){
  
          if ($request-&gt;user()-&gt;user_type !== 'man')
          {
              return redirect('/');
          }
          $user_permissions = Auth::user()-&gt;permissions;
          foreach($user_permissions as $value){
              $controller = Controllers::get_controller($value-&gt;controller_id);
              $permissions['name'] = $controller-&gt;controller_name;
  
              $all_permissions[] = $permissions;
              unset($permissions);
          }
          foreach ($all_permissions as $value){
              $controllers[] =  trim($value['name']);
          }
          $request-&gt;user()-&gt;controllers = $controllers;
  
          return $next($request);
  
      }
      else{
          return redirect('/login');
      }
  }
  </code></pre>
  
  <p>So I get a list of all user permissions which represent controllers names and in every controller (in this controller i check if the user has permission named 'users' to access the users controller to view their data)</p>
  
  <pre><code>protected $user;
  
  public function __construct(){
      $this-&gt;middleware(function ($request, $next) {
          $this-&gt;user= Auth::user();
          if(!in_array('users',$this-&gt;user-&gt;controllers)){
              session()-&gt;flash('error' , 'No permission');
              return redirect('/admin');
          }
          else{
              return $next($request);
          }
      });
  }
  </code></pre>
  
  <p>I use this for every controller and it works for a small project but when it comes to a large project with modules (<a href="https://github.com/nWidart/laravel-modules" rel="nofollow noreferrer">nWidart/laravel-modules</a>) it'll be hard. What I want is to check for the permission for the whole module not for every single controller in the module. So if I have a module named blog I want to check if the logged in user has permission to access any controller in that module how could this be done?</p>