4

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

4 Answers4

11

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'))
Black
  • 18,150
  • 39
  • 158
  • 271
Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
1

Here:

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

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')) {
    //
}
Vishal
  • 639
  • 7
  • 32
0

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
}