Source: juststeveking.uk

Effective Eloquent
Get ready to level up your Laravel skills with this tutorial on eloquent queries! Eloquent is an Object Relational Mapper for Laravel and a Query Builder.

So far, we have refactored to use a query class dedicated to running a query and returning our result.

The query class returns a query builder instance, so we need to return get on the result.

final class RecentAccountsForUser implements RecentAccountsForUserContract { public function handle(Builder $query, int $days = 7): Builder { return $query->select( 'accounts.*', DB::raw('COUNT(transactions.id) as total_transactions'))->groupBy('transactions.account_id'); }}
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners