Level 70
@mdev11 You can try this:
$users = User::get();
return $users->toJson(JSON_PRETTY_PRINT, 'users');
Or
return response()->json([
'users' => User::get()
]);
This command:
User::get()->toJson();
returns:
[{"id":1,"name":"John"},{"id":2,"name":"Doe"}]
Is it possible to set a key for the response to check with js?
Like:
{"users":[{"id":1,"name":"John"},{"id":2,"name":"Doe"}]}
Alternative to:
$users = User::get();
return response()->json(['users', $users);
Please or to participate in this conversation.