Ad

Laravel 5.8 403 This Action Is Unauthorized

I have update method like this

  public function update(Contact  $contact)
{

    $this->authorize('ownItems', $contact);
    ......
}

and ContactPolicy :

public function ownItem(User $user,Contact $contact)
{
  return true;
} 

It work correctly but when I replace Contcact to ContactRequest in my update method show me this :

403 This action is unauthorized.

update method :

public function update(ContactRequest  $contact)
{
    $this->authorize('ownItems', $contact);
    .......
}

authorize method in ContactRequest:

public function authorize()
{
    return true;
}
Ad

Answer

ContactRequest is a laravel Request class instance


public function update(ContactRequest $request,Contact  $contact)
{
    $this->authorize('ownItems', $contact);
    .......
}

Ad
source: stackoverflow.com
Ad