0

I have a get formule that returns some nested relationships in an array. I was wondering how to access them in a where statement.

The initial get

$taken = UserWork::with('work.place')
            ->with('user')
            ->with('work.timeslot')
            ->get();

I tried something like this

$taak = $taken->where('work.timeslot[0].start_hour',"17:00:00")->first();

json result from $taken

json result from $taken

1
  • do u want to get the userworks records and its timeslot which start_hour is 17:00:00.Or u can post the example that u expected. Commented Apr 30, 2020 at 14:54

1 Answer 1

1

Using with will endup with two queries. if you want to bring the user with timeslot null then there no need to add whereHas

    $callback = function($query) {
        $query->where('start_hour',"17:00:00");
    };

    $taken = UserWork::whereHas('work.timeslot', $callback)
        ->with(
            ['work.place', 'user', 'work.timeslot' => $callback]
        )->get();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.