Created
October 10, 2018 17:30
-
-
Save ahmadshah/fcb2b495e750336743273bc97b7bc365 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
namespace App\Http\Controllers; | |
use App\User as UserModel; | |
class UserController extends Controller | |
{ | |
public function index() | |
{ | |
$users = UserModel::all(); | |
$response = []; | |
foreach($users as $user) { | |
$roles = $user->roles()->pluck('name'); | |
$userArray = $user->toArray(); | |
$userArray['roles'] = $roles; | |
$response[] = $userArray; | |
} | |
return response()->json($response); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment