I need to select all columns from a table and an additional columns using subquery. For example,
SELECT *, (SELECT COUNT(*) FROM transactions WHERE transactions.customer=customers.id) AS transactions FROM customers
Right now, I have come up with 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.
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3o62AoM
via IFTTT
Aucun commentaire:
Enregistrer un commentaire