@foreach (...">

Comparison of lines in Laravel 5 blades

I have this in my click file:

 <select class="form-control" name="category" id="category">
   @foreach ($category as $h)
     @if ({{$h->id}} == {{$directory->category}})
      <option value="{{$h->id}}" selected>{{$h->name}}</option>
     @else
      <option value="{{$h->id}}">{{$h->name}}</option>
     @endif
   @endforeach
</select>

and controller:

    $directory= Directory::find($id);
    $category = StoreCategory::all();
    return view('edit')->with('category', $category)->with('directory', $directory);

After opening the edit, I get a "syntax error, unexpected" <'"

I tried to remove the if-else condition and it works fine.

+4
source share
1 answer

You should not use {{ ... }}in your block if. Change it to:

@if ( $h->id == $directory->category )
+8
source

Source: https://habr.com/ru/post/1598150/


All Articles