mardi 2 avril 2019

Is it possible to check if relation was included in Eloquent?

I have model with lot of relations through one specific relation. Is it possible to check if that relation was included in builder somewhere before?

For example:

$users->when($request->get('some-thing'), function($query, $id) {
    $query->whereHas('entries.some_thing', function($_query) {
    });
})->when($request->get('other-thing'), function($query, $id) {
    $query->whereHas('entries.other_thing', function($_query) {
    });
})->when($request->get('third-thing'), function($query, $id) {
    $query->whereHas('entries.third_thing', function($_query) {
    });
});

// .......

if ($user->entries_was_not_included()) {
    $user->has('entries')
}

The idea is that to skip extra include of it already joined somewhere else.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2COI99m
via IFTTT

Aucun commentaire:

Enregistrer un commentaire