I have in my model a query to get data from the database and there are nullable fields present in my database table. When I try to display all the records in my view, the fields which are of null value, is displayed as "NULL". I want these values to be display as just empty string.
Here is what I have in my controller:
public function showDetails($action, $id)
{
$data_model= new PersonData();
$persons= $data_model->loadSpecificPerson($id);
return view('pages.admin.reporting_person_details', ['action' => $action, 'id' => $id])->with('id', $id)->with(compact('persons'));
}
In my model:
public function loadSpecificPerson($id)
{
$persons = DB::select("SELECT * FROM complainant_t WHERE ComplainantID = ?", [$id]);
return $persons;
}
I wanted to do it like how you would do it in an array:
foreach($array as $key => $value)
{
if($array[$key] == NULL)
{
$array[$key] = "";
}
}
This isn't possible to use with $persons since it's an object and must be accessed with name right? So how should I perform this without having to access it by the column names?