I'm trying to pass a predefined variable with a value into the @if part of the statement for comparison. This is for Laravel v8.0 on the blade.php. It only works if I hardcoded the value in it but not through the variable $value. I would need to have a placeholder variable to pass the value for comparison, as it will be inputted from user. Hence may I know what is the proper way to declare the variable as in this case? Sorry I'm just starting learning Laravel. Thanks for your help.
Eg:
$value = "abc123";
@foreach($surveys as $survey)
@if($survey->Unit_code == {{$value}})
<form action="" method="">
@csrf
<div class="form-group">
<label for="name">Name</label> <br>
<input type="text" name="Name" class="form-control" value="{{$survey->name}}">
</div>
<input type="submit" value="Save">
</form>
@endif
@endforeach
{{}}
around the value, as that's for putting a value into the dom, where the blade directive can handle the PHP variable already. If you need a PHP var to have a value and be set before the loop use the@php
and@endphp
view()
function