title: Laravel FormRequest validation gets User model and sometimes directly the name
body: <p>I am using Laravel 8 and validate my requests with the <a href="https://laravel.com/docs/8.x/validation#form-request-validation" rel="nofollow noreferrer">form request validation</a>. However, I have a strange problem. Before I am going to describe my problem I will paste my routes and my validation class here:</p>
  <p>routes:</p>
  <pre><code>Route::post('users', ['as' =&gt; 'user.search', 'uses' =&gt; 'UserController@indexSearch']);
  
  Route::post('user/name', ['as' =&gt; 'user.name.exists', 'uses' =&gt; 'UserController@nameExists']);
  
  Route::post('user/email', ['as' =&gt; 'user.email.exists', 'uses' =&gt; 'UserController@emailExists']);
  
  Route::post('user/email/check', ['as' =&gt; 'user.email.check', 'uses' =&gt; 'UserController@emailCheck']);
  
  Route::get('user/{user:name}', ['as' =&gt; 'user.show', 'uses' =&gt; 'UserController@show']);
  
  Route::get('user/{user:name}/einstellungen', ['as' =&gt; 'user.settings', 'uses' =&gt; 'UserController@showSettings']);
  
  Route::get('user/{user:name}/produkte', ['as' =&gt; 'user.products', 'uses' =&gt; 'UserController@userProducts']);
  
  Route::post('user/{user:name}/produkte', ['as' =&gt; 'user.products.post', 'uses' =&gt; 'UserController@userProducts']);
  
  Route::get('user/{user:name}/saved/produkte', ['as' =&gt; 'user.marked.products', 'uses' =&gt; 'UserController@userMarkedProducts']);
  
  Route::post('user/{user:name}/saved/produkte', ['as' =&gt; 'user.marked.products.post', 'uses' =&gt; 'UserController@userMarkedProducts']);
  
  Route::post('user/{user:name}/avatar/upload', ['as' =&gt; 'user.avatar.update', 'uses' =&gt; 'UserController@update']);
  
  Route::post('user/{user:name}/avatar/valid', ['as' =&gt; 'user.avatar.valid', 'uses' =&gt; 'UserController@validAvatar']);
  
  Route::post('user/{user:name}/avatar/löschen', ['as' =&gt; 'user.avatar.delete', 'uses' =&gt; 'UserController@deleteAvatar']);
  
  Route::post('user/{user:name}/update/password', ['as' =&gt; 'user.password.change', 'uses' =&gt; 'UserController@updatePassword']);
  
  Route::post('user/{user:name}/validate/password', ['as' =&gt; 'user.password.validate', 'uses' =&gt; 'UserController@validatePassword']);
  </code></pre>
  <p>This is my <code>FormRequest</code> validation which checks if the user is authorized to perform this request and if the given data are valid. As you can see, I check if the <code>Auth::user()-&gt;name</code> is the same as the requested user (<code>$this-&gt;user-&gt;name</code>) to change the image. Because only the owner of his profile image should be allowed to change is profile image.</p>
  <pre><code>class UserAvatarUpdateRequest extends FormRequest
  {
      public function authorize()
      {
          dump(array('auth' =&gt; Auth::user()-&gt;name, 'requested' =&gt; $this-&gt;user));     
  
          if(Auth::check() &amp;&amp; Auth::user()-&gt;name == $this-&gt;user-&gt;name){
              return true;
          }
  
          return false;
      }
      
      public function rules()
      {
          return [
              'avatar' =&gt; [
                  'required',
                  'image',
                  'max:5000',
                  'mimes:jpeg,png,jpg',
                  Rule::dimensions()-&gt;minWidth(200)-&gt;minHeight(200)-&gt;ratio(1)
              ],
          ];
      }
  
  }
  </code></pre>
  <p>Now I will come to the problem. As you can see I have several routes for my user and there is one route called <code>user.avatar.valid</code> and another route called <code>user.avatar.update</code>.</p>
  <p>Both routes, <code>user.avatar.valid</code> and <code>user.avatar.update</code> are using the <code>FormRequest</code> validation class I have pasted above. Basically <code>user.avatar.valid</code> is being called before the user submits the form to check if the uploaded image is valid. I know, I also could do this in one request but that's not possible because I am using <code>vee-validate</code> for Vuejs to validate if the form is valid.</p>
  <p>However, thats not the probleme here. The problem is that when calling the <code>user.avatar.valid</code> route my dump echos for the key <code>requested</code> the <code>name</code> of the requested user. But, when performing a request for <code>user.avatar.update</code> I don't get the <code>name</code> of the user but rather the user <code>object</code> which contains the <code>id</code>, <code>name</code>, <code>email</code> and so on.</p>
  <p>But exactly this is the point... when trying to call <code>user.avatar.update</code> I get a <code>403</code> error (forbidden) because <code>$this-&gt;user</code> is not equal to <code>Auth::user()-&gt;name</code>. Obviously it is not the same when I compare a <code>string</code> (name) to the user <code>object</code>.</p>
  <p>However, when calling <code>user.avatar.valid</code> it passes because here I get the <code>name</code> when calling <code>$this-&gt;user</code> and not the user <code>object</code>.</p>
  <p>But why is that?</p>
  <p>When I change <code>$this-&gt;user</code> to <code>$this-&gt;user-&gt;name</code> I get the actual name for the user when calling the <code>user.avatar.update</code> route but on the other side I get a <code>500</code> error when calling the <code>user.avatar.valid</code> route because it says <code>Trying to get property 'name' of non-object</code>...</p>
  <p>Does anybody has an idea where the problem here is and how to fix this?</p>
  <p>Kind regards and thank you!</p>