4

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.

1 Answer 1

3

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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.