@martinbean, @sinnbeck, @karam mustafa - thanks for your input. The reason I am using DB query builder is because I have users that belong to organisations (many-many). In the admin section, an admin can associate a user with multiple organisations.
That page shows one long list of all organisations, sorted firstly by organisations that the user is a member of, then organisations that the user is not a member of - with a toggle to add membership. I had a long fight with eloquent to in an attempt to get the results sorted on the child relationship - but it was not fruitful, and seems like exactly the type of task best suited to a database.
My DB query looks like this:
$usersOrgs = DB::table('organisations')
->leftJoin('organisation_user', 'organisations.id', '=', 'organisation_user.organisation_id')
->leftJoin('users', 'users.id', '=', 'organisation_user.user_id')
->select('users.*', 'organisations.*')
->where('users.id', '=', $user->id)
->orWhereNull('users.id')
->orderByRaw('-users.name DESC')
->orderBy('organisations.OrgName')
->get();
My resource route is /admin/users/{user}/organisations/{organisation}
I am most tempted to add the query to the organisations model as I think that I will be easily able to find it there in the future. I struggle to see the benefit of a separate layer as suggested by @karam mustafa - to me this is adding complexity.
Is the way I am going about this wrong in some way, am I doomed to failure / hard to maintain code like this?