Using Laravel 6 and PHP 7.4,
is it possible to check the following for non-existing data before accessing the value but together with the query? In order to avoid some cases of "Trying to get property of non-object"
(Two examples, one with query builder and one with eloquent)
DB::table('table')->where(...)->value('column');
// or
Auth::user()->someRelationship->column;
but if the value of the column is null, return maybe empty string?
Or I will have to do it in steps:
$query = DB::table('table')->where(...);
return $query->column ?? "";
// or
$query = Auth::user()->someRelationship;
return $query->column ?? "";
I remember I saw somewhere the null coalescing operator being used somehow in the query, just couldn't get it to work again