'How to use something else than "find" in the @can directive when looking for a specific model instance?
I have this policy file used for SomeModel
class SomeModelPolicy{
...
public function delete($user, SomeModel $someModel){
return $user->can('update', $someModel->someOtherBelongsToModel)
}
}
and want to use a @can directive in order to specify who should be able to delete a model via a graph ql query.
Normally, i would write something like this
@can(ability: "delete" find:id model:"App\\Models\\SomeModel")
but this specific graphql query is not selecting by id (which is primary key) but by other key called public_id.
Now, i've read in the documentation that i should use something like
@can(ability: "delete" query:true model:"App\\Models\\SomeModel")
in combination with "directives that add constraints to the query builder, such as @eq", as the docs specify, but i can make literally nothing work with the query
i've tried
@eq(key: "public_id" value:public_id)
or
@where(key:"public_id" operator:"=")
but graphql just always throws error saying
`Too few arguments to function App\\Policies\\SomeModelPolicy::delete(), 1 passed `
I have been pulling my hair for hours. The docs are really unhelpful, there are almost no examples online and the Lighthouse's error message is not helpful at all, providing a vague message with an irrelevant stack trace.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
