CRUD orderBy 与关系
CRUD orderBy with relationship
我很难按相关值对 CRUD 行进行排序。在我的主要案例中,我想根据相关状态
的权重来排序工作
Job (table)->status_id ---> Status (table)->weight
我已经正确设置了 belongsTo 和 hasMany 关系并添加/编辑等,效果很好,我只是不知道如何设置 $this->crud->orderBy()
这与按关系对任何 Laravel 模型进行排序没有什么不同。我认为标准方法是为此使用 Laravel's eager loading:
$this->crud->query = $this->crud->query->with(['status' => function ($query) {
$query->orderBy('weight', 'desc');
}])->get();
希望对您有所帮助!
我很难按相关值对 CRUD 行进行排序。在我的主要案例中,我想根据相关状态
的权重来排序工作Job (table)->status_id ---> Status (table)->weight
我已经正确设置了 belongsTo 和 hasMany 关系并添加/编辑等,效果很好,我只是不知道如何设置 $this->crud->orderBy()
这与按关系对任何 Laravel 模型进行排序没有什么不同。我认为标准方法是为此使用 Laravel's eager loading:
$this->crud->query = $this->crud->query->with(['status' => function ($query) {
$query->orderBy('weight', 'desc');
}])->get();
希望对您有所帮助!