laravel how to check if session variable is empty

15,812

Solution 1

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'))

Solution 2

Here:

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

Related videos on Youtube

Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin almost 2 years

    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

    • u_mulder
      u_mulder over 6 years
      It's better to prepare a variable in a controller.
  • Chuck Le Butt
    Chuck Le Butt over 4 years
    Why not just use @elseif (session('package_id'))?