You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It appears that the criteria are no longer being applied to the model.
This method is located in the BaseRepository class, which is responsible for instantiating a new instance of the model:
publicfunctionmakeModel()
{
$model = $this->app->make($this->model());
if (!$model instanceof Model) {
thrownewRepositoryException("Class {$this->model()} must be an instance of Illuminate\\Database\\Eloquent\\Model");
}
return$this->model = $model;
}
This approach seems unusual because instantiating the model in this way doesn't allow us to apply a where clause.
The solution with makeModel() is not Ok because that function is used in resetModel() and it doesn't reset the model. If you use the repository class twice it will have the previous query parameters.
My HOT fix is calling the custom reset() method before pushCriteria().
public function reset()
{
$this->model = $this->app->make($this->model())->query();
return $this;
}
$products = $productsRepository->reset()->pushCriteria(new Search($params))->paginate();
Hi,
Is anyone using the criteria in Laravel 10 ?
It appears that the criteria are no longer being applied to the model.
This method is located in the
BaseRepository
class, which is responsible for instantiating a new instance of the model:This approach seems unusual because instantiating the model in this way doesn't allow us to apply a where clause.
It's somewhat equivalent to doing this :
In this example,
app
returns an instance of the model, not ofEloquentBuilder
. I don't understand how this approach still works as intended.The only solution I've found is to implement the
makeModel
method in my repository class, which is not ideal :Does anyone have a better idea?
The text was updated successfully, but these errors were encountered: