Search code examples
phplaravellaravel-bladephp-7

Blade: Invalid argument supplied for foreach()


sometimes $structures array has the null value the same code for other variable is working fine but not in this case.

@foreach($structures ?? [] as $item) {{ $item }} @endforeach


Solution

  • I resolved the issue by adding () around $structures ?? [] expression.

    @foreach(($structures ?? []) as $item) {{ $item }} @endforeach