title: Declaration of App\Http\Requests\UserUpdateRequest::user() should be compatible with Illuminate\Http\Request::user($guard = NULL)
body: <p>I am trying to back and implement FormRequest objects for validation. I have successfully setup the form requests for all of my models except for the User model. I am getting the following error <code>Declaration of App\Http\Requests\UserUpdateRequest::user() should be compatible with Illuminate\Http\Request::user($guard = NULL)</code>. Researching this error it seems like it may be an issue with the way that I'm handling the authorization through Policies. Note that the <strong>UserStoreRequest</strong> works but the <strong>UserUpdateRequest</strong> returns the error. </p>
  
  <p><strong>UserStoreRequest</strong></p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Requests;
  
  use App\User;
  use Illuminate\Foundation\Http\FormRequest;
  use Illuminate\Support\Facades\Gate;
  
  class UserStoreRequest extends FormRequest
  {
      /**
       * Determine if the user is authorized to make this request.
       *
       * @return bool
       */
      public function authorize()
      {
          // Authorize action - create-user
          return Gate::allows('create', User::class);
      }
  
      /**
       * Get the validation rules that apply to the request.
       *
       * @return array
       */
      public function rules()
      {
          return [
              'name'      =&gt; 'required|string',
              'email'     =&gt; 'required|email|unique:users',
              'password'  =&gt; 'required|string|min:8|confirmed',
              'markets'   =&gt; 'required|array',
              'roles'     =&gt; 'required|array',
          ];
      }
  
      /**
       * Save the user.
       *
       * @return \App\User
       */
      public function save()
      {
          // Create the user
          $user = new User($this-&gt;validated());
  
          // Set the password
          $user-&gt;password = Hash::make($this-&gt;validated()['password']);
          $user-&gt;setRememberToken(Str::random(60));
  
          // Save the user
          $user-&gt;save();
  
          // Set users markets
          $user-&gt;markets()-&gt;sync($this-&gt;validated()['markets']);
  
          // Update the users role if included in the request
          if ($this-&gt;validated()['roles']) {
              foreach ($this-&gt;validated()['roles'] as $role) {
                  $user-&gt;roles()-&gt;sync($role);
  
                  if ($user-&gt;hasRole('admin')) {
                      $user-&gt;markets()-&gt;sync(Market::all());
                  }
              }
          }
  
          return $user;
      }
  
      /**
       * Get the error messages for the defined validation rules.
       *
       * @return array
       */
      public function messages()
      {
          return [
              'name.required'      =&gt; 'The name is required.',
              'email.required'     =&gt; 'The email is required.',
              'email.unique'       =&gt; 'The email must be unique.',
              'password.required'  =&gt; 'The password is required.',
              'password.confirmed' =&gt; 'The passwords do not match.',
              'password.min'       =&gt; 'The password must be at least 8 characters.',
              'markets.required'   =&gt; 'A market is required.',
              'roles.required'     =&gt; 'A role is required.',
          ];
      }
  }
  </code></pre>
  
  <p><strong>UserUpdateRequest</strong></p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Requests;
  
  use Illuminate\Foundation\Http\FormRequest;
  use Illuminate\Support\Facades\Gate;
  
  class UserUpdateRequest extends FormRequest
  {
      /**
       * Determine if the user is authorized to make this request.
       *
       * @return bool
       */
      public function authorize()
      {
          // Authorize action - update-user
          return Gate::allows('update', $this-&gt;user);
      }
  
      /**
       * Get the validation rules that apply to the request.
       *
       * @return array
       */
      public function rules()
      {
          return [
              'name'     =&gt; 'required|string',
          ];
      }
  
      /**
       * Get the user from the route.
       *
       * @return \App\User
       */
      public function user()
      {
          return $this-&gt;route('user');
      }
  
      /**
       * Save the email role.
       *
       * @return \App\Role
       */
      public function save()
      {
          // Update the user
          $this-&gt;user-&gt;update($this-&gt;validated());
  
          // // Check to see if password is being updated
          // if ($this-&gt;validated()['password']) {
          //     $this-&gt;user-&gt;password = Hash::make($this-&gt;validated()['password']);
  
          //     $this-&gt;user-&gt;setRememberToken(Str::random(60));
          // }
  
          // // Set users markets
          // $this-&gt;user-&gt;markets()-&gt;sync($this-&gt;validated()['markets']);
  
          // // Set users roles
          // // // Update the users role if included in the request
          // if ($this-&gt;validated()['roles']) {
          //     foreach ($this-&gt;validated()['roles'] as $role) {
          //         $this-&gt;user-&gt;roles()-&gt;sync($role);
  
          //         if ($this-&gt;user-&gt;hasRole('admin')) {
          //             $this-&gt;user-&gt;markets()-&gt;sync(Market::all());
          //         }
          //     }
          // }
  
          // // Save the user
          // $this-&gt;user-&gt;save();
  
          return $this-&gt;user;
      }
  
      /**
       * Get the error messages for the defined validation rules.
       *
       * @return array
       */
      public function messages()
      {
          return [
              'name.required'      =&gt; 'The name is required.',
              'email.required'     =&gt; 'The email is required.',
              'email.unique'       =&gt; 'The email must be unique.',
              'markets.required'   =&gt; 'A market is required.',
              'roles.required'     =&gt; 'A role is required.',
          ];
      }
  }
  </code></pre>
  
  <p>As you can see I have commented out most of the code for the UpdateRequest for troubleshooting. It seems that the issue is with the <code>authorize()</code> method. Below is the code from the <strong>UserPolicy</strong></p>
  
  <p><strong>UserPolicy</strong></p>
  
  <pre><code>/**
   * Determine whether the user can create models.
   *
   * @param \App\User $user
   *
   * @return mixed
   */
  public function create(User $user)
  {
      return $user-&gt;hasPermission('create-user');
  }
  
  /**
   * Determine whether the user can update the model.
   *
   * @param \App\User $user
   * @param \App\User $model
   *
   * @return mixed
   */
  public function update(User $user, User $model)
  {
      return $user-&gt;hasPermission('update-user');
  }
  </code></pre>
  
  <p><strong>UserController</strong></p>
  
  <pre><code>/**
   * Store a newly created resource in storage.
   *
   * @param \Illuminate\Http\UserStoreRequest $request
   *
   * @return \Illuminate\Http\Response
   */
  public function store(UserStoreRequest $request)
  {
      return redirect($request-&gt;save()-&gt;path());
  }
  
  /**
   * Update the specified resource in storage.
   *
   * @param \Illuminate\Http\UserUpdateRequest $request
   * @param \App\User                          $user
   *
   * @return \Illuminate\Http\Response
   */
  public function update(UserUpdateRequest $request, User $user)
  {
      return redirect($request-&gt;save()-&gt;path());
  }
  </code></pre>
  
  <p>I'm using a permission based authorization for this system. The user has the <code>hasPermission()</code> method on it to verify if the user has the required permission to perform the action. I fear that I've confused myself on this setup and that I am not validating correctly. Everything has worked up until trying to implement this on the User model. </p>
  
  <p><strong>hasPermission()</strong></p>
  
  <pre><code>/**
   * Check to see if the model has a permission assigned.
   *
   * @param string $permission
   *
   * @return bool
   */
  public function hasPermission($permission)
  {
      if (is_string($permission)) {
          if (is_null(Permission::whereName($permission)-&gt;first())) {
              return false;
          } else {
              return $this-&gt;hasRole(Permission::where('name', $permission)-&gt;first()-&gt;roles);
          }
      }
  
      return $this-&gt;hasRole($permission-&gt;roles);
  }
  </code></pre>
  
  <p><strong>hasRole()</strong></p>
  
  <pre><code>/**
   * Check to see if model has a role assigned.
   *
   * @param string $role
   *
   * @return bool
   */
  public function hasRole($role)
  {
      if (is_string($role)) {
          return $this-&gt;roles-&gt;contains('name', $role);
      }
  
      return (bool) $role-&gt;intersect($this-&gt;roles)-&gt;count();
  }
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>I have tried renaming the <code>user()</code> method in <strong>UserUpdateRequest</strong> to <code>frank()</code> to resolve any issues overriding the <strong>Request</strong> user. This clears up the error listed above, but then the response is returned unauthorized. The logged in user has permissions set to allow updating users. This is called in the <code>authorize()</code> method using <code>Gate::allows</code>. I'm just not sure if it's checking the logged in user or the model user. </p>
  
  <p>I investigated further and found that there is a new error after changing the method to <code>frank()</code>. I am getting <code>Call to a member function update() on null</code>. I should be returning the user pulled from the route from the frank method but it seems to be returning null. </p>
  
  <p><strong>Updated UserUpdateRequest</strong></p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Requests;
  
  use Illuminate\Foundation\Http\FormRequest;
  use Illuminate\Support\Facades\Gate;
  
  class UserUpdateRequest extends FormRequest
  {
      /**
       * Determine if the user is authorized to make this request.
       *
       * @return bool
       */
      public function authorize()
      {
          // Authorize action - update-user
          return Gate::allows('update', $this-&gt;frank);
      }
  
      /**
       * Get the validation rules that apply to the request.
       *
       * @return array
       */
      public function rules()
      {
          return [
              'name'     =&gt; 'required|string',
          ];
      }
  
      /**
       * Get the user from the route.
       *
       * @return \App\User
       */
      public function frank()
      {
          return $this-&gt;route('user');
      }
  
      /**
       * Save the email role.
       *
       * @return \App\Role
       */
      public function save()
      {
          // Update the user
          $this-&gt;frank-&gt;update($this-&gt;validated());
  
          // // Check to see if password is being updated
          // if ($this-&gt;validated()['password']) {
          //     $this-&gt;user-&gt;password = Hash::make($this-&gt;validated()['password']);
  
          //     $this-&gt;user-&gt;setRememberToken(Str::random(60));
          // }
  
          // // Set users markets
          // $this-&gt;user-&gt;markets()-&gt;sync($this-&gt;validated()['markets']);
  
          // // Set users roles
          // // // Update the users role if included in the request
          // if ($this-&gt;validated()['roles']) {
          //     foreach ($this-&gt;validated()['roles'] as $role) {
          //         $this-&gt;user-&gt;roles()-&gt;sync($role);
  
          //         if ($this-&gt;user-&gt;hasRole('admin')) {
          //             $this-&gt;user-&gt;markets()-&gt;sync(Market::all());
          //         }
          //     }
          // }
  
          // // Save the user
          // $this-&gt;user-&gt;save();
  
          return $this-&gt;frank;
      }
  
      /**
       * Get the error messages for the defined validation rules.
       *
       * @return array
       */
      public function messages()
      {
          return [
              'name.required'      =&gt; 'The name is required.',
              'email.required'     =&gt; 'The email is required.',
              'email.unique'       =&gt; 'The email must be unique.',
              'markets.required'   =&gt; 'A market is required.',
              'roles.required'     =&gt; 'A role is required.',
          ];
      }
  }
  </code></pre>