I've created a materialized view: accounts_index
that has a couple left joins, so I need to do a group by with the eloquent model. I also need to paginate the collection and am having trouble nailing the order of things. The materialized view:
CREATE materialized VIEW accounts_index
AS SELECT a.account_uuid,
a.account_no,
a.person_owner_uuid,
a.company_owner_uuid,
a.account_group_uuid,
a.account_scope_uuid,
a.created_at,
a.deleted_at,
s.service_uuid,
s.status,
st.service_type
FROM accounts a
LEFT JOIN services s
ON a.account_uuid = s.account_uuid
LEFT JOIN service_types st
ON s.service_type_uuid = st.service_type_uuid
The eloquent model can grab that table like so: AccountIndex::all();
.
I could paginate that: AccountIndex::paginate();
or do a groupBy: AccountIndex::all()->groupBy('account_uuid');
, but lost on how to combine the two. Some attempts:
AccountIndex::all()->groupBy('account_uuid')->paginate()
:Method Illuminate\Database\Eloquent\Collection::paginate does not exist.
AccountIndex::paginate()->groupBy('account_uuid');
: returns the collection without paginating.$accountsIndex = collect(\DB::table('accounts_index')->get()); $accountsIndex->groupBy('account_uuid')->paginate();
: SameMethod Illuminate\Support\Collection::paginate does not exist.
exception.
The main problem I'm trying to solve is that these joins will be returning accounts that have multiple services (so multiple rows) and I need to then group by the account_uuid
. Thanks in advance for any insights!