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

chavsohi's avatar

session not working in controller

when i try to store a value in session in a controller which make a connect to an API (ex:glosbe) session not saving any thing. i don have problem with controllers that is not connect to an API. i am using laravel 5.3

my question with detail in stack overflow : http://stackoverflow.com/questions/43836814/laravel5-3-session-not-working-in-controllers-class/43842641#43842641

0 likes
12 replies
al0mie's avatar

You can check that your route is under the web middleware, and check if session starts at that point.

chavsohi's avatar

yes it's on the web middleware . how can i check session is start or not?

Jaytee's avatar

Okay so just to clarify a few things:

  1. Your route service provider should include the route middleware. If it does, then the web middleware should not be applied to any routes that you have created. If it doesn't, then you need to apply the web middleware to your routes.

  2. Are any errors thrown or is it just a blank page? instead of echoing the session, use dd(session('name')) and see what the results are.

  3. Make sure of course, you're actually creating the session by visiting the URL that stores the session and then try view it on the home page.

1 like
chavsohi's avatar

thank @Jaytee for reply ; I don't have any problem with session for controllers that don't connect to any API . i have problem with session, just in a controller that connect to Glosbe API or oxford API or any other API ....

i checked my route service it was fine, i try dd(session('name')) and return null

@Jaytee , if you have time, try to connect to an API(ex:oxford,Glosbe) and then save result in session and see do you have any problem or not.

Snapey's avatar

Are you sure you are not on 5.4? I know this may seem a strange question but the API routes don't invoke sessions.

Snapey's avatar
Snapey
Best Answer
Level 122

Actually applies to 5.3 also

The api.php file contains routes that the RouteServiceProvider places in the api middleware group, which provides rate limiting. These routes are intended to be stateless, so requests entering the application through these routes are intended to be authenticated via tokens and will not have access to session state.

chavsohi's avatar

thank @Snapey for answer me, so when oxford API or Glosbe API or any other API send data to my app. my app don't start session and i can't store anything in session.

is any way to start session in such a situation ?

Snapey's avatar

can you route them via web.php instead?

Snapey's avatar

Well API is stateless so there is no session. How are you authenticating the connection?

chavsohi's avatar

thank you guy's for reply . i don't using session any more.

Please or to participate in this conversation.