Reputation: 1073
I have two tables:
Orders Recipient
I need to get all rows from table Orders
and select only one related row from table Recipient
.
Now I created addiction between tabled. But when I get full all rows:
foreach($orders as $u){
$recipients[] = $u->recipient;// Here all rows for user = 1
}
Upvotes: 0
Views: 75
Reputation: 6276
By the questions its not clear what is the criteria for searching the recipients. Suppose you want to get all the orders with some particular id and then you want to search recipients with particular id then you can do following:
$orders = Order::find($id);
$recipient = $orders->recipient()->whereId($recipient_id);
return $recipient;
Don't forget to have models with the name of Orders and Recipient, must have imported the class in the file, and must have relationship and mass assignment. It works fine with the One to Many relationship, you can have it accordingly.
Upvotes: 1