vendredi 30 novembre 2018

How to retrieve information through table?

I have SQL query that does that I need:

SELECT users.FirstName, users.Id FROM `orders` 
INNER JOIN orderrecipients ON orderrecipients.Orders_Id = orders.Id
INNER JOIN users ON users.Id = orderrecipients.Users_Id;

I try to use Eloquent model to build query above using hasManyThrough:

public function OrderRecipients()
{
 return $this->hasManyThrough('App\OrderRecipient', 'App\Order', 'Id', 'Orders_Id');
}

And using is:

$recipients = OrderModel::with("OrderRecipients")->where("User_Id", $userId)->get();
dd($recipients->OrderRecipients()->count());

How to build this relation and get data through table?



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

Aucun commentaire:

Enregistrer un commentaire