Laravel error handling when route does not exist
<p>I have a route to show my users' profile in my laravel project. But when you go to an url and fill in a username that does not exist it gives a nasty error, obviously because that username doesn't exist in the database.</p>

<p>Has anyone any idea how I can error handle this?</p>

<p>Here's my route:</p>

<pre><code>Route::get('user/{name}', 'userController@showUser');
</code></pre>

<p>Here's my function:</p>

<pre><code>public function showUser($name)
    {
        $user = User::where('name' , '=', $name)-&gt;firstOrFail();
        return view('user.show', compact('user'));
    }
</code></pre>

<p>This is what I've tried but doesn't seem to work since I get this error:
View not found</p>

<pre><code>$user = User::where('name' , '=', $name)-&gt;first();
        if(!empty($user)){
            return view('user.show', compact('user','projects'));
        }else{
            return view('user');
        }
</code></pre>