Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

abduljakul-salsalani's avatar

How to query from a related model with foreign key id.

I have 2 tables :

Users and Couriers

> users 
id | email | password | username | You know what I mean


> couriers

id  |  user_id(FK) | status | no_of_parcels

I have to get the currently logged_on user which has an Id of 3 in the User model with that. if I have a user_id of 3 in the couriers table which has the id of 280

Then In My query :

$id = something like_ auth()->user()->couriers_matched_Id of the user_id which is 280

$package = Parcel::with('owner')->where([ ['courier_id','=',$id ], ['delivery_date','=',$today] ])->get();

I have to get the corresponding id depending upon the currently logged on id.

0 likes
1 reply

Please or to participate in this conversation.