I have this in my blade 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);
Upon opening edit, I am getting "syntax error, unexpected '<'"
Tried removing the if-else condition and it is working fine.
The assignment operator assigns the variable on the left to have a new value as the variable on right, while the equal operator == tests for equality and returns true or false as per the comparison results. Example: This example describes the string comparison using the == operator.
Answer: Use the PHP strcmp() function You can use the PHP strcmp() function to easily compare two strings. This function takes two strings str1 and str2 as parameters. The strcmp() function returns < 0 if str1 is less than str2 ; returns > 0 if str1 is greater than str2 , and 0 if they are equal.
The strcmp() function compares two strings. Note: The strcmp() function is binary-safe and case-sensitive. Tip: This function is similar to the strncmp() function, with the difference that you can specify the number of characters from each string to be used in the comparison with strncmp().
ِYou shouldn't use {{ ... }}
in your if
block. Change it to:
@if ( $h->id == $directory->category )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With