相关疑难解决方法(0)

Get Specific Columns Using "With()" Function in Laravel Eloquent

I have two tables, User and Post. One User can have many posts and one post belongs to only one user.

In my User model I have a hasMany relation...

public function post(){
    return $this->hasmany('post');
}
Run Code Online (Sandbox Code Playgroud)

And in my post model I have a belongsTo relation...

public function user(){
    return $this->belongsTo('user');
}
Run Code Online (Sandbox Code Playgroud)

Now I want to join these two tables using Eloquent with() but want specific columns from the second table. I know I can use the Query …

php orm laravel eloquent laravel-query-builder

165
推荐指数
9
解决办法
20万
查看次数

标签 统计

eloquent ×1

laravel ×1

laravel-query-builder ×1

orm ×1

php ×1