Hi BhavinShah2010, try json_encode helper:
json_encode(DB::table('users')->get()->toArray()); // convert any array to json object
, but I advise to make this through Eloquent model User::all()
, output of collection automatically will be in JSON format object
I you want to use the json data in the controller, use jasonrust's code.
If you want to use it as a json reply, just return the array in your controller method. The view will take care of the rest.
Hello, jasonrust
You mean to say like this ,
return json_encode(User:all());
Thank You.
LaurentMeganck , Yes.
I have to pass the json format data to somewhere using API. so can I use json array instead of json Object?
BhavinShah2010 said:
Hello, jasonrust
You mean to say like this ,
return json_encode(User:all());
Thank You.
If u need json as string I advise to use ->toJson()
method on collection, example:
User::all()->toJson();
Hello jsonrust, I want data in JSON Object and then want to send JSON Object to somewhere using API.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community