Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rogeriorossi's avatar

Session only available in local class

I'm using Laravel 11 and to pass sessions from pure php to laravel application, I use curl with POST method and call the route:

Route::post('/api/store-session', function (Request $request) {

session(['access' => $request->input('access')]);
session(['usertype' => $request->input('usertype')]);

return response()->json(['status' => 'Session stored']);

})->withoutMiddleware([VerifyCsrfToken::class]);

When I do a dd(session('access')) inside the route, I obtain the value stored in session. But when I try to use this session in a view, the value is null.

I'm using database method to store sessions.

How can I get the session value from rroute to view?

0 likes
1 reply
rogeriorossi's avatar

I figure out how to pass $_SESSION values into Laravel project.

In my login.php page (non-laravel) I put a call to a route and send the information via POST.

In web.php route file, I put the route:

Route::post('/api/store-session', function (Request $request) {

session(['access' => $request->input('access')]);
session(['usertype' => $request->input('usertype')]);

return response()->json(['status' => 'Session stored']);
})->withoutMiddleware([VerifyCsrfToken::class]);

In my view I use the code:

@php

$access = session('access');
$usertype = session('usertype');

dd($access, $usertype);

@endphp

The problem now is:

When I do a dd(session('access')), for example, inside the route, I obtain the value stored in session. But when I try dd($access, $usertype) in my view, the value returns null.

How can I get the values of sessions inside my view?

Please or to participate in this conversation.