title: Laravel API, how to properly handle errors
body: <p>Anyone know what is the best way to handle errors in Laravel, there is any rules or something to follow ?</p>
  
  <p>Currently i'm doing this : </p>
  
  <pre><code>public function store(Request $request)
  {
    $plate = Plate::create($request-&gt;all());
  
    if ($plate) {
      return $this-&gt;response($this-&gt;plateTransformer-&gt;transform($plate));
    } else {
      // Error handling ?
      // Error 400 bad request
      $this-&gt;setStatusCode(400);
      return $this-&gt;responseWithError("Store failed.");
    }
  }
  </code></pre>
  
  <p>And the setStatusCode and responseWithError come from the father of my controller :</p>
  
  <pre><code>public function setStatusCode($statusCode)
  {
      $this-&gt;statusCode = $statusCode;
  
      return $this;
  }
  
  public function responseWithError ($message )
  {
      return $this-&gt;response([
          'error' =&gt; [
              'message' =&gt; $message,
              'status_code' =&gt; $this-&gt;getStatusCode()
          ]
      ]);
  
  }
  </code></pre>
  
  <p>But is this a good way to handle the API errors, i see some different way to handle errors on the web, what is the best ?</p>
  
  <p>Thanks.</p>