Joey93
Joey93

Reputation: 103

Syntax error, unexpected ':', expecting '(' in Laravel

I have done some googling on this error I have an it seems to be an error in the blade templates but I cannot see what I have done that is different to my other templates that work. This is the error message

FatalErrorException in 66e07bb82defb1810fc6e13b82dc623493bf38fa.php line 11:
syntax error, unexpected ':', expecting '('

This is the line of code in the file that I have not touched that is showing as an error in my IDE

<?php if: ?> 

and finally here is my view that triggers the error message when I submit the form.

    @extends('templates.default')

@section('content')
<div class="col-md-6 col-md-offset-3">
            <h3>Your Account</h3>
            <form action="{{ route('profile.avatar') }}" method="post" enctype="multipart/form-data">
                <div class="form-group">
                    <label for="image">Image (only .jpg)</label>
                    <input type="file" name="image" class="form-control" id="image">
                </div>
                <button type="submit" class="btn btn-primary">Save Account</button>
                <input type="hidden" value="{{ Session::token() }}" name="_token">
            </form>
</div>
@stop

templates.default

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
    </head>
    <body>
        @include('templates.partials.navigation')
        <div class="container">
            @include('templates.partials.alerts')
            @yield('content')
        </div>
    </body>
</html>

Upvotes: 1

Views: 15629

Answers (3)

user2538273
user2538273

Reputation: 61

Forgetting to type the complete syntax expected by the directives of laravel blade template control structures can cause this. For instance the following will produce the same error that the OP came across:

@if (count($data) == 0)
    //do something
@elseif
    //do something else
@endif

while the following code does not:

@if (count($data) == 0)
    //do something
@else
    //do something else
@endif

The @elseif part expects a condition to evaluate and upon finding nothing the blade template parser goes bonkers.

Upvotes: 6

Joey93
Joey93

Reputation: 103

The function that was being called was redirecting me to another view that I had not checked, when I realised it was redirecting me upon submitting the form I then checked the view and it had a stray @if in it which was causing the error.

Upvotes: 0

Alexey Mezenin
Alexey Mezenin

Reputation: 163758

You shouldn't use anything like <?php if: ?>. If you want to use conditions inside Blade templates, do something like this:

@if($a == 2)
    A is 2
@endif

Read here for more information.

Upvotes: 0

Related Questions