Reputation: 43
I am fetching a data from model using eloquent using User::find(1);
How can i convert this to json in laravel method
Is there any way to get it from laravel.
Upvotes: 4
Views: 3450
Reputation: 11310
You should use toJson
method
So you will be adding return User::find(1)->toJson();
to your code.
Read more about toJson
here
Update :
If you need to get the result as array format then you should use toArray
return User::find(1)->toArray();
Upvotes: 3