How can I change my controller to return html content with entities as a string?
I'm receiving html with html entities in one of my callback values for examples
{content: "<p><strong>PART TIME MAINTENANCE</strong>"}
I think the solution involves using this.
HTML::decode('<h1>Hello</h1>');
Here is what my controller is doing, I don't quite understand how to make it return what I want.
class JobController extends Controller{
public function index(){
$dt = Carbon::now();
return Response::json(Jobs::where("page_location","=","InternalJobPosting")->where("active","=","1")->where('start_date',"<=",$dt)->where("end_date",">=",$dt)->get(),200);
}
public function show($id){
return Response::json(Jobs::where("id","=",$id)->first(),200);
}
}
After spending some time I figured out I could map the data returned into an array and transform the html entities using html_entity_decode().
public function index(){
$dt = Carbon::now();
$jobs = Jobs::where("page_location","=","InternalJobPosting")->where("active","=","1")->where('start_date',"<=",$dt)->where("end_date",">=",$dt)->get()
->map(function ($job) {
return [
'id'=>$job->id,
'active'=>$job->active,
'content'=>$job->content,
'category'=>html_entity_decode($job->category),
'page_location'=>$job->page_location,
'page_title'=>$job->page_title,
'start_date'=>$job->start_date,
'end_date'=>$job->end_date,
];
});
return Response::json($jobs,200);
}
public function show($id){
$job = Jobs::where("id","=",$id)->get()
->map(function ($job) {
return [
'id'=>$job->id,
'active'=>$job->active,
'content'=>html_entity_decode($job->content),
'category'=>$job->category,
'page_location'=>$job->page_location,
'page_title'=>$job->page_title,
'start_date'=>$job->start_date,
'end_date'=>$job->end_date,
];
});
return Response::json($job->first(),200);
}