You can use isset()
@if(isset($variable))
{{ $variable->title }}
@endif
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I've show method in controller that gets some status from the log table,Problem is sometimes this status didn't created yet so it give me Attempt to read property "user" on null so any idea how can i make condition on it to be !=null
public function show($id)
{
$status = Log::where('permit_id', $id)->orderBy('id', 'DESC')->latest()->first()->status;
$OGSign = Log::where('status', 'pa-init')->where('permit_id', $id)->latest()->first()->user->name;
$GuadSign = Log::where('status', 'guard-a')->where('permit_id', $id)->latest()->first()->user->name;
return view('permit.show', compact('OGSign', 'GuadSign'));
}
When i create the report log status is pa-init so its never be null but when i use show and the status of OGSign didn't created yet it gives Attemp to read on null so how i make conidition on the query
try with null safe operator
$GuadSign = Log::where('status', 'guard-a')->where('permit_id', $id)->latest()->first()->user?->name;
// blade
{{ $GuadSign ?? 'N/A' }}
Please or to participate in this conversation.