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
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
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:
@elseif (session()->get('package_id'))
Here:
$value = $request->session()->get('package_id', function () {
return 'Return this if session key does not exist';
});
As of now Laravel 8.XX there are several ways:
To determine if an item is present in the session, you may use the has method. The has method returns true if the item is present and is not null.
if (session()->has('users')) {
//
}
To determine if an item is present in the session, even if its value is null, you may use the exists method.
if (session()->exists('users')) {
//
}
To determine if an item is not present in the session, you may use the missing method.
if (session()->missing('users')) {
//
}
You Can Check By Using It
if(session()->has('my_variable')) {
// my_variable exists
} else {
// my_variable does not exist
}
You Can Also Use This Way
if(empty(session('my_variable'))) {
// my_variable is empty
} else {
// my_variable is not empty
}