dimanche 4 décembre 2016

Laravel json response: response()->json() or $var->toJson()

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)



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2g95Oqe
via IFTTT

Aucun commentaire:

Enregistrer un commentaire