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'); }}