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
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 changingQuote::class
in your code to'quote'
(same name as the variable in the URL), that should pass the object.The
view
gate is for viewing a specific item. As such, it requires passing a specificQuote
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.