It seems like you're encountering an issue where $getTitle_Data is null, which means that the query you're running is not returning any results. This could be due to the fact that there is no Assetwidget with a currentstatus of '0' and an id that matches the $id you're providing.
Here's how you can debug and handle this situation:
- Ensure that the
$idvariable is set correctly and that it corresponds to an existing record in your database. - Check your
Assetwidgetmodel and database table to make sure that there is a record that matches the conditions you're querying for. - Modify your code to handle the case where no record is found.
Here's an updated version of your code with added checks:
$getTitle_Data = Assetwidget::where('currentstatus', '0')
->where('id', $id)
->first();
if ($getTitle_Data) {
$dataasset = $getTitle_Data->title;
} else {
// Handle the case where no record was found
// You could return a default value or throw an exception
$dataasset = 'No title found for the given ID';
}
return $dataasset;
In this updated code, we first check if $getTitle_Data is not null before trying to access its title property. If $getTitle_Data is null, we set $dataasset to a default message or handle it as needed for your application.
Remember to replace the default message or handling with whatever is appropriate for your application's needs. If you expect a title to always be present, you might want to log this as an error or throw an exception instead of returning a default message.