How to get booking list with matching with users of any company in laravel

We have company and their users. We want to get all booking list with users of a company.

Please suggest how can we solve this issue.

Let's something like this


In where like


1 answer

  • answered 2019-04-15 12:19 HerickC

    I think you need this:

    $company_id = 1;
    $booking=Booking::with('users' => function ($query) use ($company_id) {
        $query->where('company_id', $company_id);

    It's in Documentation, the name of this is "Constraining Eager Loads"