Reputation: 7105
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;
}
Upvotes: 0
Views: 6407
Reputation: 12391
ContactRequest
is a laravel Request
class instance
public function update(ContactRequest $request,Contact $contact)
{
$this->authorize('ownItems', $contact);
.......
}
Upvotes: 2
Reputation: 445
You misspelled method name in $this->authorize('ownItems', $contact);
, it should be "ownItem"
ContactRequest
is probably instance of Illuminate\Http\Request
but authorize
method waiting for Model
instance, if you do not have model identifier in yout request. first you should to find model: $model = Contact::find($contact->input('id'))
and than check your policy with $this->authorize('ownItems', $model)
Upvotes: 1