How to store data temporarily to be used later in Laravel 9

How to store data temporarily to be used later in Laravel 9

Posted by Luke Beeno on July 16, 2022

How to store data temporarily to be used later in Laravel 9

How to store data temporarily to be used later in Laravel 9

Posted by Luke Beeno on July 16, 2022

In order to store data temperarily to be used later in Laravel 9, you can use the Session Helper or Request instance.

Session Helper

Here is how you store the data:

session(['name' => 'Dean']);

Here is how you retrieve the data:

$name = session('name');

or

Request

Here is how you store the data:

public function getData(Request $request, $id)
{
  $request->session()->put('name', 'Dean');
  ...
}

Here is how you retrieve the data:

public function show(Request $request, $id)
{
  $name = $request->session()->get('name');
  ...
}