1

Hello i have this function

 $TableB1 = \DB::table('users')
    ->join('group_user', 'users.id', '=', 'group_user.user_id')
    ->join('groups', 'groups.id', '=', 'group_user.group_id')
    ->select(
       'groups.name as groupname',
       'group_user.user_id as id',
       'users.name as name',
       'users.company_id as companyID'
       )
    ->get();

it get data from db and display the data in view like this

what i want to do is to group the data by group.name so the team field appear in order like
Table

Team Ahmed
Team Ahmed
Team Hassan

but when i use groupBy('group.name') i get an error in laravel

1 Answer 1

7

try orderBy().

 $TableB1 = \DB::table('users')
->join('group_user', 'users.id', '=', 'group_user.user_id')
->join('groups', 'groups.id', '=', 'group_user.group_id')
->select(
   'groups.name as groupname',
   'group_user.user_id as id',
   'users.name as name',
   'users.company_id as companyID'
   )->orderBy('groupname')
->get();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.