I use laravel medialibrary. In my model, i create method, which return Colleaction
public function colors()
{
return $this->getMedia('colors');
}
in my scheme i add
colors: [Media] @hasMany(relation: "colors")
sample query
query {
item {
name
colors {
id
}
}
}
getting an error: Method Illuminate\Support\Collection::addEagerConstraints does not exist.
How best to implement custom relation?
Your colors function doesn't return a relationship, but just a collection. So, your schema should be:
...
colors: [Media!] @method(name: "colors")
...
@enzonotario, thanks!
Most helpful comment
Your
colorsfunction doesn't return a relationship, but just a collection. So, your schema should be: