How to Get All Session Data in Laravel?

Hi,

This is a short guide on laravel get all session data. I explained simply about how to get all session data in laravel. We will use laravel get all session data example. you will learn get all session data in laravel.

You can use this example with laravel 6, laravel 7, laravel 8 and laravel 9 version.

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

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

Example 1: using session() helper

we will get all session using session() helper function:

Controller Code:

<?php

namespace AppHttpControllers;

use IlluminateHttpRequest;

class DemoController extends Controller

{

/**

* Write code on Method

*

* @return response()

*/

public function index()

{

$allSessions = session()->all();

dd($allSessions);

}

}

Output:

How to Get All Session Data in Laravel?

Example 2: using Session facade

we will get all session using Session facade:

Controller Code:

<?php

namespace AppHttpControllers;

use IlluminateHttpRequest;

use IlluminateSupportFacadesSession;

class DemoController extends Controller

{

/**

* Write code on Method

*

* @return response()

*/

public function index()

{

$allSessions = Session::all();

dd($allSessions);

}

}

Output:

How to Get All Session Data in Laravel?

I hope it can help you…

Leave a Comment