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?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire