user4607306
user4607306

Reputation: 43

How to convert the data to json format using Laravel

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

Answers (1)

Sulthan Allaudeen
Sulthan Allaudeen

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

Related Questions