title: Using a policy's this->authorize() check in a laravel controller inside a store() method
body: <p>So I was reading about using laravel policies for granting authorities on the resources of my application but there seems to be a problem there though I followed the tutorial.</p>
  
  <p>I have a user model which can't be created via HTTP requests except by other users who have the <strong>Entrust</strong> role of 'Admin' or 'Broker'. What I understood and succeeded to make it work on other actions like indexing users was the following:</p>
  
  <p>Inside the <code>AuthServiceProvider.php</code> inside the private <code>$policies</code> array, I registered that User class with the <code>UserPolicy</code> class like that</p>
  
  <pre><code>class AuthServiceProvider extends ServiceProvider {
  
      protected $policies = [
          'App\Model' =&gt; 'App\Policies\ModelPolicy',
          User::class =&gt; UserPolicy::class,
          Insured::class =&gt; InsuredPolicy::class
      ];
  
      public function boot(GateContract $gate)
      {
          $this-&gt;registerPolicies($gate);
      }
  }
  </code></pre>
  
  <p>Define the UserPolicy controller class:</p>
  
  <pre><code>class UserPolicy {
  
      use HandlesAuthorization;
  
      protected $user;
  
      public function __construct(User $user) {
          $this-&gt;user = $user;
      }
  
      public function index(User $user) {
          $is_authorized = $user-&gt;hasRole('Admin');
          return $is_authorized;
      }
  
      public function show(User $user, User $user_res) {
  
          $is_authorized = ($user-&gt;id == $user_res-&gt;id);
          return $is_authorized;    
      }
  
      public function store() {
          $is_authorized = $user-&gt;hasRole('Admin');
          return $is_authorized;
      }
  }
  </code></pre>
  
  <p>Then inside the <code>UserController</code> class, before performing the critical action I use <code>this-&gt;authorize()</code> check to halt or proceed depending on the privilege of the user</p>
  
  <pre><code>class UserController extends Controller
  {
  
      public function index()
      {
          //temporary authentication here
          $users = User::all();
          $this-&gt;authorize('index', User::class);
          return $users;
      }
  
      public function show($id)
      {
          $user = User::find($id);
          $this-&gt;authorize('show', $user);
          return $user;
      }
  
      public function store(Request $request) {
  
  
          $user = new User;
          $user-&gt;name = $request-&gt;get('name');
          $user-&gt;email = $request-&gt;get('email');
          $user-&gt;password = \Hash::make($request-&gt;get('password'));
  
          $this-&gt;authorize('store', User::class);
  
          $user-&gt;save();
  
          return $user;
  
      }
  }
  </code></pre>
  
  <p><strong>The problem</strong> is that <code>$this-&gt;authorize()</code> always halts the process on the store action returning exception: This action is unauthorized.</p>
  
  <p>I tried multiple variations for arguments of the authorize() and can't get it to work like the index action </p>