The solution to this problem is to make sure that the session is started before setting or getting any values from it. In Laravel, the session is started automatically, but if you are using a custom session driver, you may need to manually start the session.
To set a value in the session, you can use the session() helper function or the Session facade. To get a value from the session, you can use the session() helper function or the Session facade.
Here's an example of how to use the session between controllers:
In the first controller:
if (Auth::attempt($credentials)) {
session(['key' => 'value']);
}
In the second controller:
public function test(Request $request)
{
if ($request->session()->has('key')) {
dd($request->session()->get('key'));
}
}
Make sure that the session middleware is applied to all routes that use the session. You can do this by adding the middleware to the $middleware property of the App\Http\Kernel class:
protected $middleware = [
// ...
\Illuminate\Session\Middleware\StartSession::class,
];