Home > Blockchain >  How to use query sql for show parent table in laravel
How to use query sql for show parent table in laravel

Time:07-28

How to display room rates using mysql query?

I have 2 tables, namely the room table and the rental rate table, I want to display the rental rates for each room.

table room

table rental rate

How to call it with mysql query ? i have tried using grouping, join. But it didn't work. Please help

CodePudding user response:

In your Room model add this relationship:

    public function rates()
    {
        return $this->hasMany(RentalRate::class);
    }

In Controller call:

$rooms = Room::with('rates')->get();

Read more about Laravel Relationships

  • Related