Table structure should be
hotels
id
name
hotel_rooms
id
hotel_id
name
hotel_packages
id
hotel_room_id
name
hotel_package_rates
id
hotel_package_id
value
started_at
ended_at
You can use Has Many Through relationship for that
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Hotel extends Model
{
public function packages()
{
return $this->hasManyThrough('App\Models\HotelPackage', 'App\Models\HotelRoom');
}
}
To get packages by hotel:
$hotel = Hotel::with('packages')->findOrFail(100);
$packages = $hotel->packages;
To get rates by hotel:
$hotel = Hotel::with('packages')->findOrFail(100);
$packageRates = HotelPackageRate::wherenIn('hotel_package_id', $hotel->packages->pluck('id'))->get();
Docs: https://laravel.com/docs/8.x/eloquent-relationships#has-many-through