How to Get All Session Data in Laravel?

Today now in this post i will show you how to get all session data in laravel? So this is a very short guide on laravel how to get all session data. Here I will explained this simply about how we can get all session data in laravel. So we will use here laravel get all session data example. From here you will learn about get all session data in laravel.

We can also use this example with laravel 6, laravel 7, laravel 8 and laravel 9 any version.

If we want to get all session data in laravel application then here I will help you with how to get it.we know Laravel is provides session() helper or Session facade to getting all the session data in laravel. we can get session all data in the blade file also , controller file, model file, etc.

Here I will give you two examples, so let’s start and see them one by one.

Example 1: using session() helper

You can get all session by using session() helper function:

Controller Code:

<?php
    
namespace App\Http\Controllers;
    
use Illuminate\Http\Request;
  
class DemoController extends Controller
{
    /**
     * Write code on Method
     *
     * @return response()
     */
    public function index()
    {
        $allSessions = session()->all();
        dd($allSessions);
    }
}
Example 2: using Session facade

You can also get all session by using Session facade:

Controller Code:

<?php
    
namespace App\Http\Controllers;
    
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Session;
  
class DemoController extends Controller
{
    /**
     * Write code on Method
     *
     * @return response()
     */
    public function index()
    {
        $allSessions = Session::all();
        dd($allSessions);
    }
}

Read Also: How To Implement Laravel 9 form validation ?

Thanks for read. I hope it help you. For more you can follow us on facebook

close

About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →