skip to Main Content

I am using middelware to call policies on a certain model:

Route::get('check-document-exist/{quote}/{type}', 'DocumentController@checkDocumentExistence')
    ->can('view', Quote::class);

This is the concerned method of the policy:

public function view(User $user, Quote $quote): bool
{
    return true;
}

the first argument which is the user is passed in the arguments array but the second argument is not retrieved by the policy view method.

How can I solve this issue, please?

2

Answers


  1. The public function view(User $user, Quote $quote) expects the 2nd argument to be the object of Quote, but you’re passing a name of the class (string Quote::class) instead. Try changing Quote::class in your code to 'quote' (same name as the variable in the URL), that should pass the object.

    Login or Signup to reply.
  2. The view gate is for viewing a specific item. As such, it requires passing a specific Quote model, not the class itself.

    If you want to check the user’s ability to view any of this sort of item, use the viewAny check instead.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search