语法错误,意外的“:”,在 Laravel 中期待“(”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36617836/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Syntax error, unexpected ':', expecting '(' in Laravel
提问by Joey93
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
这是我没有触及的文件中的代码行,它在我的 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
模板.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>
回答by user2538273
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:
忘记输入 laravel 刀片模板控制结构指令所期望的完整语法会导致这种情况。例如,以下将产生与 OP 遇到的相同错误:
@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.
该@elseif
部分期望评估条件,并且在发现任何内容时刀片模板解析器会发疯。
回答by Alexey Mezenin
回答by Joey93
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.
被调用的函数将我重定向到另一个我没有检查过的视图,当我意识到它在提交表单时重定向我然后我检查了视图,它有一个流浪的 @if 导致错误。