How to Get All Session Data in Laravel?

By Hardik Savani April 16, 2024 Category : 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, laravel 9, laravel 10 and laravel 11 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 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);

}

}

Output:

Example 2: using Session facade

we will get all session 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);

}

}

Output:

I hope it can help you...

Tags :
Shares