mardi 28 novembre 2017

laravel eloquent merge 2 queries before executing them?

I have 2 queries like this:

$expiresAt = Carbon::now()->addMinutes(10);
$thumbnails = Cache::remember('entities-thumbnails-'.$entity_id, $expiresAt, function () use ($entity_id) {
    return Images::where(['entity_id' => $entity_id, 'image_style' => 'thumbnail'])
        ->select('path AS thumbnail', 'width As thumbnailWidth', 'height As thumbnailHeight');
});
$largeImages = Cache::remember('entities-largeImages-'.$entity_id, $expiresAt, function () use ($entity_id) {
    return Images::where(['entity_id' => $entity_id, 'image_style' => 'large'])
        ->select('path AS src')
        ->union($thumbnails)
        ->get();
});

What I want to do is not execute them seperately but as one query. Overall there will be 4 queries therefore instead of doing 4 I want to do one, is that possible? How does union work exactly?



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

Aucun commentaire:

Enregistrer un commentaire