Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 1 year ago.
0

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 1 year ago.
0

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 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

lasseal lasseal Joined 19 Jul 2014

Moderators

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

Your logo here?

Laravel.io

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

© 2024 Laravel.io - All rights reserved.