How to return custom API response for "No query results for model", Laravel
<p>I am building an RESTful API in Laravel 5.2.</p>

<p>In my resource controllers I want to use implicit model binding to show resources. e.g.</p>

<pre><code>public function show(User $users)
{
    return $this-&gt;respond($this-&gt;userTransformer-&gt;transform($users));
}
</code></pre>

<p>When a request is made for a resource that doesn't exist Laravel automatically returns the NotFoundHttpException</p>

<p><a href="https://i.stack.imgur.com/3ZQfp.png" rel="nofollow noreferrer">NotFoundHttpException</a></p>

<p>I want to return my own custom response but how can I do that for a query that is done using route model binding?</p>

<p>Would something like this <a href="https://stackoverflow.com/q/28645259/2349608">Dingo API response answer</a> be able to be implemented?</p>

<p>Or will I stick with my old code which was something like this:</p>

<pre><code>public function show($id)
{
    $user = User::find($id);

    if ( ! $user ) {
        return $this-&gt;respondNotFound('User does not exist');
    }

    return $this-&gt;respond($this-&gt;userTransformer-&gt;transform($users));
}
</code></pre>

<p>So I could see if a resource (user) was not found and return an appropriate response.</p>