I'm using Laravel (in fact Lumen) for my API. I have created a User
model and I use this to retrieve all my users:
$users = User::all()
Now I want to return it as json but when I read the Laravel site I see two options. Which one is the best and why, and what is the difference?
return response()->json($users)
(as described here)
return $users->toJson()
(as described here)
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire