laravel version is 5.4
1, there is such a code, as follows
$this->model->with('article')->get()
2, the sql statement being executed now is
select * from article where..
I want the sql statement to be executed as
select id,title from user where..
How to implement it
Methods I’ve tried
$this->model->with(['user' => function($query){
$query->select('id','article');
}])->get()
OR
public function user() {
$query->belongTo(Article::class)->select('id', 'title');
}
Will not work
I haven’t tried it, but you can refer to this Laravel related query to get only part of the data of the managed object