samedi 2 mars 2019

Laravel filter relation's data by other relations data

I am trying to filter my tickets.tips.drawDates relation's data by other relation's column (results.draw_date) in an eager-loading query. Does anybody have any advice on how to accomplish that?

$products = Product::with([
        'results' => function ($query) use ($drawDates) {
            return $query->whereBetween('draw_date', $drawDates);
        },
        'tickets' => function ($query) use ($drawDateFrom) {
            return $query->whereDate('valid_until', '>=', $drawDateFrom)->where('status', 'pending');
        },
        'tickets.tips',
        'tickets.tips.drawDates' => function($query) {
            return $query->whereNull('status')->whereDate('draw_date', 'HERE SHOULD BE draw_date COLUMN FROM results RELATION');
        },
        'prizes'
    ])->get();



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire