How to Get All Session Data in Laravel?

About Us:

We are from free coder. We are a group of web developers who are passionate about web development. You can learn from us php, laravel, node js, vue js, react js and many other topic on web developement.
we are very happy to help you.
free coder

Today what you are going to learn:

Hello Brother,

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 lesson. you will learn get all session data in laravel.

You can use this lesson 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 lessons, so let's see them one by one.

Lesson 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);

}

}

Result:-

Lesson 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);

}

}

Result:-

thank you very much for following up with me.

Tags

Recent Posts

Related Posts