title: Laravel: Redirect the user to a custom 404 page when the given params are invalid
body: <p>I made an application where a user can create some papers and see all data in a template. Every paper has a <strong>joincode</strong> which is generated at its creation.</p>
  <p>I defined the join route in my <strong>web.php</strong> like this:</p>
  <pre><code>Route::get('/conceptPaper/lobby/{joincode}', 'App\Http\Controllers\ConceptPaperController@join');
  </code></pre>
  <p>and the join function in the controller the following way:</p>
  <pre><code>public function join($joincode)
      {
          try { 
              $conceptPaper = ConceptPaper::where('join_code', $joincode)-&gt;firstOrFail();
              return response()-&gt;json($conceptPaper);
          } catch(ModelNotFoundException $e)
          {
              return view('errors.404');
          }
      }
  </code></pre>
  <p>I used <strong>firstOrFail</strong> to check if the join code exists. If it exists it should return a response, otherwise it should redirect the user to a custom 404 page.</p>
  <p>I created a custom component which gets the join code as a route param and shows the concept paper</p>
  <pre><code>{
          path: '/conceptPaper/lobby/:joincode',
          name: 'conceptPaper',
          component: () =&gt; import('./views/ConceptPaper.vue')
      },
  </code></pre>
  <p>So when the user joins a lobby with the right code he gets redirected to the page with all data from the corresponding paper:</p>
  <pre><code>showPaper: async function (conceptPaper) {
        const joinCode = conceptPaper.join_code;
        this.$router.push({ name: &quot;conceptPaper&quot;, params: { joincode: joinCode }, });
      },
  </code></pre>
  <p>My problem is that when the user types in the wrong code he still gets redirected to the view. When I check the response in the network tab its shows the 404 page.</p>
  <p>I think I built it fundamentally wrong. Can anyone tell me how to do it the right way? When the suer types in the correct join code he should see the <strong>ConceptPaper.vue</strong> view. When the code is wrong he should be redirected to the 404 page.</p>