语法错误,意外的“:”,在 Laravel 中期待“(”

Joe*_*y93 0 laravel laravel-5.2 laravel-blade

我已经对这个错误进行了一些谷歌搜索,我有一个似乎是刀片模板中的错误,但我看不出我所做的与我的其他工作模板不同。这是错误信息

FatalErrorException in 66e07bb82defb1810fc6e13b82dc623493bf38fa.php line 11:
syntax error, unexpected ':', expecting '('
Run Code Online (Sandbox Code Playgroud)

这是我没有触及的文件中的代码行,它在我的 IDE 中显示为错误

<?php if: ?> 
Run Code Online (Sandbox Code Playgroud)

最后这是我提交表单时触发错误消息的视图。

    @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
Run Code Online (Sandbox Code Playgroud)

模板.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>
Run Code Online (Sandbox Code Playgroud)

小智 5

忘记输入 laravel 刀片模板控制结构指令所期望的完整语法会导致这种情况。例如,以下将产生与 OP 遇到的相同错误:

@if (count($data) == 0)
    //do something
@elseif
    //do something else
@endif
Run Code Online (Sandbox Code Playgroud)

而下面的代码没有:

@if (count($data) == 0)
    //do something
@else
    //do something else
@endif
Run Code Online (Sandbox Code Playgroud)

@elseif部分需要一个条件来评估,并且在没有发现任何东西时刀片模板解析器会发疯。