Skip to main content
Category:

Sub-selects in Laravel Way


From Laravel 6, you can use addSelect() in Eloquent statement, and do some calculation to that added column.

return Destination::addSelect(['last_flight' => Flight::select('name')
           ->whereColumn('destination_id', 'destinations.id')
            ->orderBy('arrived_at', 'desc')
           ->limit(1)
])->get();

Riadh Rahmi

Senior Web Developer PHP/Drupal & Laravel

I am a senior web developer, I have experience in planning and developing large scale dynamic web solutions especially in Drupal & Laravel.

Web Posts

Search

Page Facebook