Home > database >  Getting syntax error,unexpected token "<" in laravel blade file
Getting syntax error,unexpected token "<" in laravel blade file

Time:12-20

Getting syntax error,unexpected token "<" in laravel blade file.

code in my blade file,

 @if( {{ date('Y-m-d')}} >= {{ $date->start_date }} && {{ date('Y-m-d')}} <= {{ $date->end_date }} )

                 <a href="form"  id="apply"><span>Apply</span></a>

               @else

                 <b>Form date closed.</b>
                 
               @endif

If the condition is true the button will be display. otherwise the else part will display.

CodePudding user response:

It looks like there are some extra curly braces in your @if statement. In Blade templates, you don't need to use curly braces to print out the value of a variable or to run a function. You can simply use the @ symbol to indicate that what follows is a Blade construct.

Here's how you can rewrite your code to fix the syntax error:

Copy code

@if(date('Y-m-d') >= $date->start_date && date('Y-m-d') <= $date->end_date)
    <a href="form"  id="apply"><span>Apply</span></a>
@else
    <b>Form date closed.</b>
@endif

Note that you don't need to use echo to print out a value in a Blade template. Just using the variable or function name is enough.

  • Related