Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vandan's avatar
Level 13

Empty variable check in blade file

blade file

@foreach($student as $students)

@if(students->studentname=="null)

condion true

@else

Condition False

@endif

@endforeach

Controller file

public function view() { $student=Student::all();

return view('view',compact('student));

}

0 likes
2 replies
richard's avatar

What are you trying to achieve in those if statements? Do you mean there are students who do not have names? :)

First of all, you need to do @foreach($students as $student) and not the other way round.

STEREOH's avatar

@RICHARD - well to be fair he did pass his students collection as "student" so his code is not wrong , just unreadable.

Please or to participate in this conversation.