mercredi 30 décembre 2015

get related model without loop query

tables:

products:

id | name | author_id    

authors:

id | name

models:

product:

public function author() {
    return $this->belongsTo('App\Author');
}

Then I get products:

$products = Product::where('name','like','username%')->get();
foreach ($products as $product) {
    $product->author;
}

Is there any way to get products with author without loop?



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

Aucun commentaire:

Enregistrer un commentaire