if - else 在 laravel 框架刀片模板中不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27603802/
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
if - else does not work in laravel framework blade templating
提问by Ali insan Soyaslan
My question is, I have page as Laravel blade template. If user logged in, my page should be extended from a master layout. If user did not login, my page should be extended from another master layout.
我的问题是,我有一个页面作为 Laravel 刀片模板。如果用户登录,我的页面应该从主布局扩展。如果用户没有登录,我的页面应该从另一个主布局扩展。
But my if- else statement does not working
但是我的 if-else 语句不起作用
<?php
if (Auth::check()){?>
@extends('layouts.outside');
<?php } else{ ?>
@extends('layouts.admin');
<?php }?>
I also tried blade if-else version as follows:
我还尝试了刀片 if-else 版本如下:
@if (Auth::check())
@extends('layouts.outside')
@else
@extends('layouts.admin')
@endif
It did not work too. Every time wheter the statement true or false the block in if and else statement works one after. As there is no if else. I mean every time it calls layouts.outside one time one and just bottom of it the same page is loaded again with layouts.outside, whether not matter if the user logged in or not.
它也不起作用。每次无论语句是真还是假,if 和 else 语句中的块都会在之后起作用。因为没有如果。我的意思是每次它一次调用 layouts.outside 并且在它的底部再次使用 layouts.outside 加载同一页面,无论用户是否登录都无关紧要。
Thanks
谢谢
采纳答案by AddcitedToLearn
<?php
if (Auth::check()){
Blade::extends('layouts.outside');
<?php } else
extends('layouts.admin');
}?>
You are missing a { at the else also why that php tag remove it
您在其他位置缺少 { 也是为什么该 php 标记将其删除
<?php
if (Auth::check()){
Blade::extends('layouts.outside');
} else{
extends('layouts.admin');
}
?>
回答by matematikistan
@extends(Auth::user() ? 'layouts.outside' : 'layouts.admin');