Laravel Blade双花括号不起作用

时间:2019-05-29 17:57:03

标签: laravel laravel-blade

通过阅读Laravel文档,我了解到我应该能够使用{{ }}来转义我的字符串。但是,这样做会出错,但是如果运行{!! !!},则字符串可以正常工作。我的代码中缺少什么?

代码刀片文件(login.blade.php)的完整视图

@extends('layouts.app')

@section('content')
		<div class="kt-grid kt-grid--ver kt-grid--root">
			<div class="kt-grid kt-grid--hor kt-grid--root  kt-login kt-login--v3 kt-login--signin" id="kt_login">
				<div class="kt-grid__item kt-grid__item--fluid kt-grid kt-grid--hor" style="background-image: url({{ asset('assets/media//bg/bg-3.jpg);">
					<div class="kt-grid__item kt-grid__item--fluid kt-login__wrapper">
						<div class="kt-login__container">
							<div class="kt-login__logo">
								<a href="#">
									<img src="assets/media/logos/logo-5.png">
								</a>
							</div>
							<div class="kt-login__signin">
								
								<div class="kt-login__head">
									<h3 class="kt-login__title">Sign In To Account</h3>
								</div>

                                <form class="kt-form" method="post" action="/login">
									
								{!! csrf_field() !!}
									
								<div class="input-group">
										<input class="form-control" type="text" placeholder="Email" name="email" value="" autocomplete="off">
									</div>

									<div class="input-group">
										<input class="form-control" type="password" placeholder="Password" name="password">
									</div>
									
									@if ($errors->any())

										@foreach($errors->all() as $error)
											<p>{!! error !!}</p>
										@endforeach
									
									@endif

									<div class="row kt-login__extra">
										<div class="col">
											<label class="kt-checkbox">
												<input type="checkbox" name="remember"> Remember me
												<span></span>
											</label>
										</div>
										<div class="col kt-align-right">
											<a href="javascript:;" id="kt_login_forgot" class="kt-login__link">Forget Password ?</a>
										</div>
									</div>
									<div class="kt-login__actions">
										<button id="kt_login_signin_submit" class="btn btn-brand btn-elevate kt-login__btn-primary">Sign In</button>
									</div>
								</form>
							</div>

							<div class="kt-login__account">
								<span class="kt-login__account-msg">
									Don't have an account yet ?
								</span>
								&nbsp;&nbsp;
								<a href="" id="kt_login_signup" class="kt-login__account-link">Sign Up!</a>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
@endsection

错误

  

ErrorException(E_ERROR)语法错误,意外的't'(T_STRING),   期待','或')'(查看:   C:\ xampp \ htdocs \ test \ resources \ views \ auth \ login.blade.php)上一页   异常语法错误,意外的“ t”(T_STRING),预期为“,”或   ')'(0)

1 个答案:

答案 0 :(得分:0)

您需要使用双括号将“ error”变量设置为变量。否则,它被视为未定义的常量。

@foreach($errors->all() as $error)
    <p>{{ $error }}</p>
@endforeach

您还需要在asset()帮助函数中为URL添加右大括号和右单引号。

<div class="kt-grid__item kt-grid__item--fluid kt-grid kt-grid--hor"
    style="background-image: url({{ asset('assets/media/bg/bg-3.jpg') }}">