Answers for "How to reuse parts of Eloquent builder in Laravel"

0

How to reuse parts of Eloquent builder in Laravel

$shared = TableA::join('tableb', 'tablea.bid', '=', tableb.id)
           ->join('talbec', 'tableb.cid', '=', tablec.id)
           ->join('tabled', 'tablec.did', '=', tabled.id);

$a = $shared->clone()->where('tablea_col', '=', true)->get();

$b = shared->clone()->where('tableb_col', '=', true)->get();
before Laravel 8, use

$a = clone $shared;
$b = clone $shared;
$a = $a->where('tablea_col', '=', true)->get();
$b = $b->where('tableb_col', '=', true)->get();
Posted by: Guest on May-09-2022

Code answers related to "How to reuse parts of Eloquent builder in Laravel"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language