@gurpreetindybytes Laravel provides the following methods in which you can store the session:
- file
- cookie
- database
- memcached / redis
- array
All this is configurable and can be found in the config/Session.php file.
Thanks.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi, I am new in laravel and I want to create a session when my angular app call my login API. Please help me out how I create the session with my laravel API.
@gurpreetindybytes Laravel provides the following methods in which you can store the session:
All this is configurable and can be found in the config/Session.php file.
Thanks.
Really, your API should be stateless.
Have a look at Passport. Either way, you have to locally store a 'session' identifier. Either an API token or a session token.
@snapey actually I don't want to store anything locally. is this possible to do that?
you can add api group in your web.php file like this:
Route::middleware(['auth'])
->prefix('api')
->namespace('Api')
->as('api.')
->group(function () {
// you can write your routes here.
});
@gurpreetindybytes Either you can store the key in local-storage or a in cookie, so the the load will be on client side not on the server, helps you to scale the application easily. The way you are dealing is wrong , that is what i feel personally. According to your title it says create sessions , means load will be on the server , again what you what to store or dont want to use local storage? Your question is not clear
" I don't want to store the token in local storage it is very bad practice."
What/who gave you that idea? I believe you want stateless authentication using tokens. Best practice.
Can anybody give me some example code that how I would start the session with my passport API?
@GURPREETINDYBYTES - You must use any js library/frame-work like react js , angular js or any other , and you have to use any http client like axios , make request to your API, get the token , store it in local or cookies, use it to make subsequent request
You can find more at https://medium.com/modulr/create-api-authentication-with-passport-of-laravel-5-6-1dc2d400a7f
@GURUR I have created the session with my laravel API. it is only worked when I call that API from the browser. When i call the API using of angular API is not create the session. Same happen when I try it with cookies.
Laravel Passport is a token-based authentication package, it does not use sessions!
@PRIMORDIAL - Then is it not risky to store token in our local storage?
Please or to participate in this conversation.