简体   繁体   中英

Laravel Eloquent select in with empty

my relation in User Model

public function fullName()
{
    return $this->hasOne(UserProfile::class,'user_id','id')->where('slug', '=', 'full_name');
}

$user = User::query()with('fullName:slug')->get();

my result:

'full_name' => null

I suggest you to see the docs

When using this feature, you should always include the id column and any relevant foreign key columns in the list of columns you wish to retrieve.

$user = User::query()->with('fullName:id,slug')->get();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM