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

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners