title: How can I prevent that a Laravel controller method handle HTTP Request that doesn't have the expected parameters list?
body: <p>I am pretty new in PHP and moreover in <strong>Laravel</strong>. I came from Java and I am a Spring MVC developer. Now I am using <strong>Laravel 5.4</strong> for a project.</p>
  
  <p>I have the following doubt related to the possibility to create Laravel controller method that handle HTTP Request having a spefic list of parameters (as the controller method input parametes).</p>
  
  <p>In Spring MVC I can declare controller method that accept only request having a specific list (and type, but in PHP we have not type) of parameter instead the simple <strong>Request $request</strong> object from which extract the parameters. </p>
  
  <p>I think being able to declare the pameters list (insted the <strong>Request</strong> object and then extract from it) is much better because the code is more readable (you read the method signature and you know what it use) and also <strong>the application can not enter in a controller method if the user have not specified all the neede parmeters !!!</strong></p>
  
  <p>For example I have a request like this (representing the link to activate an account on my Laravel website sended on the e-mail after the user registration):</p>
  
  <pre><code>http://laravel.dev/activate?email=my-email@gmail.com&amp;token=cce0452d95c358b5b3b97fec5662e12e
  </code></pre>
  
  <p>I don't wan't a controller method like this:</p>
  
  <pre><code>public function activate(Request $request) {
      if ( $request-&gt;has('email') &amp;&amp; $request-&gt;has('token')) {
          $email = $request-&gt;email;
          $token = $request-&gt;token;
      }
  }
  </code></pre>
  
  <p>because:</p>
  
  <ul>
  <li><p>Looking at the input parameter I only have the <strong>Request $request</strong> object that says me nothing about what this method will use.</p></li>
  <li><p>Most important I have to manually handle the extraction of the <strong>email</strong> and of the <strong>token</strong> request parameters and check if these parameters exist in the request.</p></li>
  </ul>
  
  <p>What I desire is that if the HTTP Request doesn't contains the expected parameters list the method will not handle this request.</p>
  
  <p>I founded this solution:</p>
  
  <p>Into my <strong>web.php</strong> file I put this route:</p>
  
  <pre><code>Route::get('/activate', [ 'as' =&gt; 'activate', function() {
      return app()-&gt;make(App\Http\Controllers\RegistrationController::class)-&gt;callAction('activate', $parameters = [ 'email' =&gt; request()-&gt;email, 'token' =&gt; request()-&gt;token ]);
  }]);
  </code></pre>
  
  <p>Then this is my controller method into my <strong>RegistrationController</strong> class:</p>
  
  <pre><code>public function activate($email, $token) {
  
      echo "Email: $email"; // myemail@gmail.com
      echo "Token: $token"; // eb0d89ba7a277621d7f1adf4c7803ebc
      // do stuff
  }
  </code></pre>
  
  <p>The problem is that doing in this way I can specify the request parameters as input parameters of my controller method (making it more readable) but the main problem remain, infact I can perform an HTTP Request like this:</p>
  
  <pre><code>http://laravel.dev/activate?email=nobili.andrea@gmail.com&amp;XDEBUG_SESSION_START=14267
  </code></pre>
  
  <p>that is handled by the <strong>activate()</strong> controller method.</p>
  
  <p>I really want prevent that this method handle request that doesn't have the expected request parameters.</p>
  
  <p>Can I do it in Laravel in some way? Maybe can I modify this solution to obtain this behavior?</p>