title: Bind posted data to a model in Laravel 5.4
body: <p>I have seen other topics regarding this issue, didn't work out.</p>
  
  <p>So in Laravel 5.4 Route Model Binding, we can bind a route to a model like:</p>
  
  <p>define the route in web.php:</p>
  
  <p><strong>web.php</strong>:</p>
  
  <pre><code>Route::get('/users/{user}', UsersController@show);
  </code></pre>
  
  <p><strong>UsersController@show</strong>:</p>
  
  <pre><code>public function show(User $user){
      // now we already have access to $user because of route model binding
      // so we don't need to use User::find($user), we just return it:
      return view(users.show, compact('user'));
  }
  </code></pre>
  
  <p>The above code will work just fine, so in our controller we can return the $user without finding the user, we already have it.</p>
  
  <p>but imagine this:</p>
  
  <p><strong>web.php</strong>:</p>
  
  <pre><code>Route::patch('/users/archive', UsersController@archive);
  </code></pre>
  
  <p><strong>EDITED:</strong> <strong>now the above line makes a <em>patch</em> route</strong> and we don't have <code>{user}</code> in the route url, the user id is being posted via the form.</p>
  
  <p><strong>UsersController@archive</strong>:</p>
  
  <pre><code>public function archive(Request $request, User $user){
      // how can I access the $user here without using User::find($user);
      // I get to this action via a form which is posting `user` as a value like `5`
      dd($request-&gt;user); // this now echo `5`
      // I can do:
      // $user = User::find($request-&gt;user);
      // and it works, but is there a way to not repeat it every time in every action
  }
  </code></pre>
  
  <p>What I have tried:
  in RouteServiceProvider::boot() I have:</p>
  
  <pre><code>Route::model('user', 'App\User');
  </code></pre>
  
  <p>The above is what i have found in Google, but not working.</p>
  
  <p>I would appreciate any kind of help.</p>
  
  <hr>
  
  <p><strong>EDIT:</strong>
  It seems it's not called <code>Route Model Binding</code> anymore since we don't have the <code>{user}</code> in the <code>route</code> and that's because my code is not working, the <code>user</code> variable is being <code>post</code>ed to the controller and it's only accessible via <code>$request-&gt;user</code>.</p>
  
  <p>this <strong>is</strong> route model binding:</p>
  
  <pre><code>Route::patch('users/{user}/archive', UsersController@archive);
  </code></pre>
  
  <p>this is <strong>not</strong>:</p>
  
  <pre><code>Route::patch('users/archive', UsersController@archive);
  </code></pre>
  
  <p>since we don't have <code>{user}</code> and it's being <code>post</code>ed via the form and could be accessed only via <code>$request-&gt;user</code>.
  (please correct me if I am wrong about the definition of route model binding)</p>
  
  <p><strong>SO:</strong></p>
  
  <p>what I want to achieve in a nutshell: in every request being sent to my <code>UsersController</code>, if I am sending <code>user</code> variable as a <code>post</code> variable, it must be bounded to <code>User::findOrFail($request-&gt;user)</code> and then <code>$user</code> must be available in my controller actions.</p>
  
  <p>I want to achieve this because in every action I am repeating myself doing <code>User::findOrFail($request-&gt;user)</code> and I don't want to do that, so I want to check in every request if I have a <code>variable name</code> like a <code>model name</code>, they should be bounded.</p>