The current solution provided in the question is correct and should work as expected. However, there is a more efficient way to achieve the same result using a subquery. Here's an example:
$hotel->dmc()
->whereNotIn('user_id', function ($query) use ($hotel) {
$query->select('user_id')
->from('dmc_hotel')
->where('hotel_id', $hotel->id);
})
->paginate($perPage);
This subquery selects all the user_id values from the dmc_hotel pivot table where the hotel_id matches the current hotel's ID. Then, the main query filters out any DMCs that have a user_id in that subquery result set.
This approach should be more efficient because it only requires one database query instead of two.