title: Customizing Spatie Laravel-Permission Exception Message
body: <p>I have added the <a href="https://github.com/spatie/laravel-permission" rel="nofollow noreferrer">Saptie Laravel Permission Package</a> in a Laravel 5.8 API application. Every works fine and I get exception when a non admin user tries to access admin specific routes.</p>
  
  <p>However the default exception is rendered as HTML <code>403 User does not have the right roles</code>. Considering I am using this inside an API application, I would like to return my own custom message for such exceptions.</p>
  
  <p>I tried checking if the <code>auth()-&gt;user()-&gt;hasRole('admin')</code> but still got the same default exception page. Here's my code</p>
  
  <p>route</p>
  
  <pre><code>Route::post('products', 'ProductController@store')-&gt;middleware('role:super-admin|admin'); // create a new product
  </code></pre>
  
  <p>Controller method</p>
  
  <pre><code>if (auth()-&gt;user()-&gt;hasRole('admin')) {
  
      // create &amp; store the product
      $product = Product::create($request-&gt;all())
  
      // return new product
      $responseMessage    = 'Successful operation';
      $responseStatus     = 200;
      $productResource    = new ProductResource($product);
  
      return response()-&gt;json([
          'responseMessage'   =&gt; $responseMessage,
          'responseStatus'    =&gt; $responseStatus,
          'product'           =&gt; $productResource
      ]);
  } else {
  
      return response()-&gt;json([
          'responseMessage'   =&gt; 'You do not have required authorization.',
          'responseStatus'    =&gt; 403,
      ]);
  }
  </code></pre>
  
  <p>Why is my custom message not showing?</p>