Support the ongoing development of →
Database Eloquent
Last updated 2 years ago.

if you are in your 'Hotel' model and trying to access the guests in the hotel, then (assuming your relationships are correct , the foreign keys are set up, and the method is named 'guest') in your Hotel model you could use:

$guests = Hotel::find($hotel_id)->guest; //or 'findOrFail($user_id)' ?

Should bring back all guests associated with the hotel id.

Last updated 2 years ago.

To add some more to this:

$guests = Hotel::find($hotel_id)->guest; 

will return a Collection.

$guests = Hotel::find($hotel_id)->guest();

will return all models.

Last updated 2 years ago.

Sign in to participate in this thread!


Your banner here too?

lasseal lasseal Joined 19 Jul 2014


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.