I have a query that I call with:
$query = "select * from myTable";
$results = DB::connection('myDB')->select($query);
I want to be able to get this in the simple json format of:
[{firstColumn: firstColumnValue, secondColumn: secondColumnValue},
{firstColumn: firstColumnValue, secondColumn: secondColumnValue}]
What is the easiest way to achieve this?
As I have read here : Laravel, converting data from raw query to JSON you can just use the json_encode. Hope that one helps.
If you thought of writing web service or something related to it, then
$Response = array('success' => '1', 'result' => $yourData);
else
$Response = array('success' => '0', 'error' => 'Your Custom Errors');
return json_encode($Response);
So that you can handle it in while you retrieve according to the result.