title: Create middleware for admin user with laravel
body: <p>I build an simple app and I have Users, but some users need to have admin privilegies, so I try to create this:</p>
  
  <ol>
  <li><p>First at migration file I add boolean type - admin:</p>
  
  <p>public function up()</p>
  
  <pre><code> {
          Schema::create('users', function (Blueprint $table) {
              $table-&gt;increments('id');
              $table-&gt;boolean('admin');
              $table-&gt;string('username');
              $table-&gt;string('email')-&gt;unique();
              $table-&gt;string('password', 60);
              $table-&gt;rememberToken();
              $table-&gt;timestamps();
          });
      }
  </code></pre></li>
  </ol>
  
  <p>after that I create new middleware:</p>
  
  <pre><code>class RedirectIfNotAManager
  {
  
      public function handle($request, Closure $next)
      {
          if (! $request-&gt;user()-&gt;IsATeamManager()){
  
              return redirect('articles');
  
          }
          return $next($request);
      }
  }
  </code></pre>
  
  <p>offcource Now I need to create function IsATeamManager() at User model file:</p>
  
  <pre><code>public function IsATeamManager(){
          if ($this-&gt;is('admin') {
              return true;
          }
          return false;
  
      }
  </code></pre>
  
  <p>at Kernel.php I add manager:</p>
  
  <pre><code> protected $routeMiddleware = [
          'auth' =&gt; \App\Http\Middleware\Authenticate::class,
          'auth.basic' =&gt; \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
          'guest' =&gt; \App\Http\Middleware\RedirectIfAuthenticated::class,
          'manager' =&gt; \App\Http\Middleware\RedirectIfNotAManager::class,
  
      ];
  </code></pre>
  
  <p>At route I add:</p>
  
  <pre><code>Route::get('foo', ['middleware'=&gt;'manager', function(){
  
      return 'This Page is Only for Managers';
  
  }]);
  </code></pre>
  
  <p>Manually at phpMyAdmin I change the user admin column for some users at '1'... I log as that user,</p>
  
  <p>But when I try to go at: localhost:8888/foo I get this error:</p>
  
  <blockquote>
    <p>BadMethodCallException in Builder.php line 2071: Call to undefined
    method Illuminate\Database\Query\Builder::is()</p>
  </blockquote>
  
  <p>What I also try is to chech is authenticated user admin when i make request so I write:</p>
  
  <pre><code>public function store(Requests\ArticleRequest $request)
      {
          $article = new Article($request-&gt;all());
  
          Auth::user()-&gt;is('admin')-&gt;articles()-&gt;save($article);
  
          return redirect('articles');
      }
  </code></pre>
  
  <p>but that doesn work and I dont know why... so my request is if authenticated users have admin column true then save article... </p>
  
  <p>What you suggest? How to implement user admin at my app?</p>