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

Ev-genius's avatar

Why PHP variable not recognize in blade @if condition?

Hello!

Try to filter by day...

@php
$dn = date('N', strtotime($days)); // 1
@endphp

@foreach ($program->exercises as $exercise )
	@if ( $exercise->pivot->day_of_week === $dn )
	{{ $exercise->name }}<br>
	@endif
@endforeach

outputs nothing

but if i replace the variable with a digit

@php
$dn = date('N', strtotime($days)); // 1
@endphp

@foreach ($program->exercises as $exercise )
	@if ( $exercise->pivot->day_of_week === 1 )
	{{ $exercise->name }}<br>
	@endif
@endforeach

exercises are shown...

Whats wrong with $dn variable?

0 likes
4 replies
Snapey's avatar

Why not also lose the temporary variable?

@foreach ($program->exercises as $exercise )
	@if ( $exercise->pivot->day_of_week == date('N', strtotime($days)) )
	{{ $exercise->name }}<br>
	@endif
@endforeach

Please or to participate in this conversation.