Here is my Row Query to get the data from database.
$users = DB::table('users')->get();
I want to pass my $users array data to json format. How can I do so?
I have tried using Eloquent Model. but didn't work.
Thank You in Advance.
If you use Eloquent then you can use ->toJson();
But you are using Query builder. So you have to use php function: json_encode()
For more information see here http://php.net/manual/en/function.json-encode.php
Eloquent has a method named
->toJson()
However you're code doesn't looks like Eloquent.
json_encode?return json_encode(User:all());