Open timothyoesch opened 1 week ago
Could this potentially be fixed thusly? Or do I not see an issue casting the model names into instances of the model through app()
?
public function getAllowedFields(): array
{
$model = app(static::getModel());
if($model instanceof HasAllowedFields) {
return $model::getAllowedFields();
}
// ...
}
What happened?
The methods
getAllowedFields()
,getAllowedSorts()
,getAllowedFilters()
andgetAllowedIncludes()
always return an empty array, even though I have implemented the corresponding HasAllowed contracts on the model.I'd posit that's the case, because the
getModel()
method returns a string of the model name, not an instance of the model.How to reproduce the bug
Create an api service for an existing resource, implement the
HasAllowedFilters
contract on your model adding the function getAllowedFilters returning the array of the filterable attributes and try filtering through the API. The response will always bePackage Version
3.3.2
PHP Version
8.2.20
Laravel Version
11.15.0
Which operating systems does with happen with?
Linux
Notes
No response