-
Notifications
You must be signed in to change notification settings - Fork 892
Laravel 10 criteria no longer work? #799
Copy link
Copy link
Open
Description
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:
public function makeModel()
{
$model = $this->app->make($this->model());
if (!$model instanceof Model) {
throw new RepositoryException("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.
It's somewhat equivalent to doing this :
app(User::class)->whereNotNull('verified_at')->get();In this example, app returns an instance of the model, not of EloquentBuilder. 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 :
class UserRepositoryEloquent extends BaseRepository implements UserRepository
{
public function model()
{
return User::class;
}
public function makeModel()
{
$model = $this->app->make($this->model());
return $this->model = $model->query();
}
public function boot()
{
$this->pushCriteria(app(RequestCriteria::class));
}
}Does anyone have a better idea?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels