Support the ongoing development of Laravel.io →
Database Eloquent Queues
Last updated 2 years ago.
0

append ->toJson() you also have toArray()

Last updated 2 years ago.
0

I tired ->get()->toJson() and it gives me the following error

Call to undefined method Illuminate\Database\Query\Builder::toJson()

Last updated 2 years ago.
0

toJson only works with Eloquent

e.g., Users::all()->toJson();

Otherwise if you are using the Query Builder then you can use the PHP json_encode() method.

E.g., json_encode(DB::table('users')->get());

Last updated 2 years ago.
0
return Response::json($users);
Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

kyoukhana kyoukhana Joined 28 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.