Created
October 12, 2018 12:19
-
-
Save adbrsln/bb834e89781a56c8b12375230c0f6750 to your computer and use it in GitHub Desktop.
UserController
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$users = User::all(); | |
$response = []; | |
foreach($users as $user) { | |
$userArray = $user->toArray(); | |
$roles = $user->roles()->select(array('id', 'role_name'))->get(); | |
$states = $user->states_val()->select(array('id', 'state_name'))->get(); | |
$credits = $user->credits()->withPivot('amount')->get(); | |
$companies = $user->companies()->get(); | |
foreach($roles as $role) { | |
$userArray['roles'] = $role; | |
} | |
foreach($states as $state) { | |
$userArray['states'] = $state; | |
} | |
foreach($credits as $credit) { | |
$userArray['credits'] = $credit; | |
} | |
foreach($companies as $company) { | |
$userArray['companies'] = $company; | |
} | |
$response[] = $userArray; | |
} | |
return response()->json($response,200); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment