<select id="year" name="year" class="form-control "> {{ $last= date('Y')-120 }} {{ $now = date('Y') }} @for ($i ={{ $now }}; $i <= {{ $last }}; $i--) <option value="{{ $i }}">{{ $i }}</option> @endfor </select>
And I got the error message Parse error: syntax error, unexpected '<'
It look like the variable can`t read.
How to set the value in the for-loop?
The blade templating engine provides loops such as @for, @endfor, @foreach, @endforeach, @while, and @endwhile directives. These directives are used to create the php loop equivalent statements.
Laravel later introduced a great helper function __() which could be used for JSON based translations. For instance, in your blade files, {{ __('The Web Tier') }} Whereas “The Web Tier” is added in a JSON file inside of resources/lang directory i.e {locale}.json likeso, {
Basically {{ $last= date('Y')-120 }}
in this part you are showing the value but you need to assign the value. So assign like this :
<?php $last= date('Y')-120; ?>
Same thing goes for the for loop too.Just compare the value. Do not put it in blade syntax.
<select id="year" name="year" class="form-control "> {{ $last= date('Y')-120 }} {{ $now = date('Y') }} @for ($i = $now; $i >= $last; $i--) <option value="{{ $i }}">{{ $i }}</option> @endfor </select>
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