laravel 如何检查会话变量是否为空

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47228939/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 16:57:05  来源:igfitidea点击:

laravel how to check if session variable is empty

phplaravellaravel-5bladelaravel-session

提问by Ghadah Salman

How can I check if this session is empty, here example

如何检查此会话是否为空,这里是示例

 @elseif {{Session::get('package_id')}}=null
 @include('index.customer.customerpackage')

and how to check if {{Session::get('package_id')}}=1 then Free else Paid

以及如何检查 {{Session::get('package_id')}}=1 然后 Free else Paid

回答by Marcin Nabia?ek

You can use

您可以使用

@elseif (session()->has('package_id'))

to verify if it's in session or in case it might be in session but also set to null, you can use:

要验证它是否在会话中,或者如果它可能在会话中但也设置为 null,您可以使用:

@elseif (session()->get('package_id'))

回答by Rafael Herculano

Here:

这里:

$value = $request->session()->get('package_id', function () {
    return 'Return this if session key does not exist';
});