Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
157
rated 0 times [  164] [ 7]  / answers: 1 / hits: 29360  / 11 Years ago, sun, may 19, 2013, 12:00:00

Hy all, can anyone help me with converting some data which will be return from model(based on the RAW query) into JSON.



So in my controller i have something like:



public function get_index() {
$data = Something::getDataFromRawQuery();

return View::make('....')->with('data', $data);
}


So my question is how to forward JSON data to the view from controller?



Here is the query:



$apps = DB::query('SELECT a.name,
a.desc,
a.sig,
ar.rate
FROM something a
INNER JOIN something_else ar
ON (a.id=ar.something_id)
ORDER BY ar.rate DESC'
);

return $apps;

More From » php

 Answers
21

DB::query returns a simple array, so just call json_encode directly on it:



$data = Something::getDataFromRawQuery();

return View::make('....')->with('data', json_encode($data));

[#78135] Friday, May 17, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tierney

Total Points: 45
Total Questions: 101
Total Answers: 94

Location: Sudan
Member since Thu, May 7, 2020
4 Years ago
;