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’ )
}
2
Q
Join with querybuilder
A
$categories = DB::table(‘categories’) ->join(‘users’,’categories.user_id’,’users.id’)->select(‘categories.* ‘ , ‘users.name’)