Answer the question
In order to leave comments, you need to log in
Does the policy always return false?
Policy in Laravel always returns false.
Method in controller:
public function destroy(Model $model, DestroyModel $request)
{
//
}
public function authorize()
{
$model = Model::find($this->route('model'));
return $model && $this->user()->can('delete', $model);
}
public function delete(User $user, Model $model)
{
return $user->id === $model->user_id;
}
Answer the question
In order to leave comments, you need to log in
Error in Laravel documentation. It says to use $this->route('blabla'). In theory, it should return the value of the parameter, but due to the auto-completion function, the model is immediately inserted there, and not the value of the parameter. So if you use autocomplete, do this:
$model = $this->route('model');
return $model && $this->user()->can('delete', $model);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question