vendredi 23 juin 2017

Laravel eager loading with join on other table

can i change this code to syntax of has_many or has_one or ... to write beautiful code?

\App\User::with(['books' => function ($query) {
    $query->join('locations','location_id','=','locations.id')
    ->select([
        'books.*',
        'locations.name as l_name'
    ]);
}])->get()

Class User:

public function books()
{
    return $this->hasMany(Book::class);
}



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2sJULZd
via IFTTT

Aucun commentaire:

Enregistrer un commentaire