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

peterlee's avatar

session ( [ $sessionKey => $sessionValue ] ); does not work

Hi,

I just write that code

session ( [ $sessionKey => $sessionValue ] );

on login process with middleware called StartSession.php

it seems works fine when that API is called though from the postman.

but it does not work when called from android application

I double checked if there is any difference between two HTTP request

but url, body, content-type all those are exactly same.

Have you ever faced this problem before?

0 likes
3 replies
bashy's avatar

Are you using the Postman cookie/session plugin to mirror them from your browser?

Normally the Laravel API won't have session included as well.

1 like
peterlee's avatar

#bashy

yep, I use Postman with cookie/session plug in, and I think those are installed as default.

and the comment you left here

Normally the Laravel API won't have session included as well.

I also add a class into api part in $middlewareGroup array in app/Http/Kernel.php

protected $middlewareGroups = [
    'api' => [
        'throttle:60,1',
        'bindings',
        \Illuminate\Session\Middleware\StartSession::class,
    ],

and successfully store session data using Postman even though it is called using Laravel API.

and I am not sure it is a proper way to do as I am a new to Laravel or Http protocol.

Could you tell me a better way to store session using Laravel API if that way is not right

Thank you in advance :)

bashy's avatar

I'm guessing the session isn't saved from Android application so it's basically resetting each time.

I can't really help past that since you're not using a RESTful API. I have no clue what you're doing with session stuff either.

1 like

Please or to participate in this conversation.