Skip to content

Instantly share code, notes, and snippets.

@ahmadshah
Created October 10, 2018 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmadshah/fcb2b495e750336743273bc97b7bc365 to your computer and use it in GitHub Desktop.
Save ahmadshah/fcb2b495e750336743273bc97b7bc365 to your computer and use it in GitHub Desktop.
<?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