Relationship Flashcards

1
Q

One to one

A

Category ->foreign key of user & connet to user
public function user( ) {
return $this->hasOne(User::class , ‘id’,’user_id’ )
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Join with querybuilder

A

$categories = DB::table(‘categories’) ->join(‘users’,’categories.user_id’,’users.id’)->select(‘categories.* ‘ , ‘users.name’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly