How to convert the data to json format using Laravel

laravel, laravel-5, php

Solution

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();

Problem

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.

Original source