[英]What is the difference between the below sample codes in Laravel 5.4
What is the difference between the two sample codes below the second returns an error I don't know why 第二个示例代码下方的两个示例代码有什么区别,返回错误,我不知道为什么
@if ( auth()->check() )
Welcome {{ Auth::user()->name }}
and this 和这个
@if ( {{auth::check() }} )
Welcome {{ Auth::user()->name }}
Both are in a blade file. 两者都在刀片文件中。 Please lets discuss this for better understanding.
请让我们讨论一下以便更好地理解。 Also please indicate which is better to use in both scenarios
还请指出哪种情况在两种情况下都更好
You shouldn't do this: 您不应该这样做:
@if ( {{auth::check() }} )
It will give you an error. 这会给你一个错误。 It's almost the same as doing this:
几乎与执行此操作相同:
if (echo(auth()->check()))
This code: 这段代码:
{{ auth()->check() }}
Will be converted to this vanilla PHP code: 将转换为以下原始PHP代码:
<?php echo e(auth()->check()); ?>
Where e()
is Laravel helper. 其中
e()
是Laravel的帮助者。
https://laravel.com/docs/5.5/blade#displaying-data https://laravel.com/docs/5.5/blade#displaying-data
They aren't the same, @if ( auth()->check() )
will check if the user is authenticated or not. 它们是不同的,
@if ( auth()->check() )
将检查用户是否已通过身份验证。 And the other @if ( {{auth::check() }} )
it's like what @Alexey said, will be converted to <?php echo e(auth()->check()); ?>
另一个
@if ( {{auth::check() }} )
就像@Alexey所说的一样,将转换为<?php echo e(auth()->check()); ?>
;。 <?php echo e(auth()->check()); ?>
and of course will return an error in your situation <?php echo e(auth()->check()); ?>
当然会在您遇到的情况下返回错误
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.