I need to select all columns from a table and an additional columns using subquery in laravel's eloquent. For example,
SELECT *, (SELECT COUNT(*) FROM transactions WHERE transactions.customer=customers.id) AS transactions FROM customers
Right now, I have come up with using a raw query using selectRaw like:
$customers = Customer::selectRaw('*, (SELECT COUNT(*) FROM transactions WHERE transactions.customer=customers.id) AS transactions')->get();
But I'd like to do it the eloquent way, without using raw queries.