All Projects → rummykhan → lumen-session-example

rummykhan / lumen-session-example

Licence: other
Enable session in lumen framework (Laravel)

Programming Languages

PHP
23972 projects - #3 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to lumen-session-example

hutplate
A Go library over standard net/http library with auth, session, err handling and more.
Stars: ✭ 28 (+27.27%)
Mutual labels:  session
paper-wallet
stellar.github.io/paper-wallet/
Stars: ✭ 41 (+86.36%)
Mutual labels:  lumen
benotes
An open source self hosted notes and bookmarks taking web app.
Stars: ✭ 260 (+1081.82%)
Mutual labels:  lumen
SanSessionToolbar
⚡ Session Toolbar that can be applied into Zend/Laminas DeveloperTools
Stars: ✭ 39 (+77.27%)
Mutual labels:  session
secure-cookie
Secure cookies and sessions for WSGI
Stars: ✭ 30 (+36.36%)
Mutual labels:  session
ocaml-cookie
Working with cookies in OCaml and Reason
Stars: ✭ 31 (+40.91%)
Mutual labels:  session
qiniu-laravel-storage
Qiniu 云储存 Laravel 5 Storage版
Stars: ✭ 520 (+2263.64%)
Mutual labels:  lumen
session
Package session is a middleware that provides the session management of Macaron.
Stars: ✭ 26 (+18.18%)
Mutual labels:  session
laravel-stateless-session
CSRF verification and session persistent through request/response headers.
Stars: ✭ 33 (+50%)
Mutual labels:  session
firebase-spring-boot-rest-api-authentication
Firebase Spring Boot Rest API Authentication
Stars: ✭ 172 (+681.82%)
Mutual labels:  session
laravel-redis-sentinel-drivers
Redis Sentinel integration for Laravel and Lumen.
Stars: ✭ 100 (+354.55%)
Mutual labels:  lumen
sessions
A non-blocking session handler for PHP
Stars: ✭ 23 (+4.55%)
Mutual labels:  session
cache
Laravel & Lumen Cache Service | File and Redis cache system
Stars: ✭ 19 (-13.64%)
Mutual labels:  lumen
dialectic
Transport-polymorphic, asynchronous session types for Rust
Stars: ✭ 60 (+172.73%)
Mutual labels:  session
Laravel-FluentLogger
fluent logger for laravel (with Monolog handler for Fluentd)
Stars: ✭ 55 (+150%)
Mutual labels:  lumen
CSRF-tutorial
Use Django To Introduce CSRF and Cookies , Session 📝
Stars: ✭ 49 (+122.73%)
Mutual labels:  session
signature
HMAC and RSA signature for Laravel and Lumen
Stars: ✭ 26 (+18.18%)
Mutual labels:  lumen
UnityCore
A collection of essential game systems for Unity 3D. These generic systems can be applied to any Unity project.
Stars: ✭ 105 (+377.27%)
Mutual labels:  session
koa-session-mongoose
Mongoose store for Koa sessions
Stars: ✭ 29 (+31.82%)
Mutual labels:  session
laravel-dynamodb-session-driver
DynamoDB Session Driver for Laravel 5
Stars: ✭ 15 (-31.82%)
Mutual labels:  session

Lumen Session Example

Example of

https://stackoverflow.com/questions/47050984/enabling-session-in-lumen-framework/47055083#47055083

Note

I've updated this repo to support to all lumen version starting from 5.6 to 8.0. All versions are in their corresponding branches whereas master branch correspond to laravel/lumen-framework 8.0.

How-To

Laravel has officially stopped supporting sessions & views in laravel/lumen framework from version 5.2 and on wards.

But laravel still have a component illuminate/session which can be installed in lumen/framework and we can play around with this.

Step - 1

install illuminate/session using

composer require illuminate/session

Step - 2

Now goto bootstrap/app.php and add this middleware

$app->middleware([
    \Illuminate\Session\Middleware\StartSession::class,
]);

Purpose of adding the above middleware is to start session on every request and save session before serving response.

Step - 3

Now add config/session.php, since it is not present in Lumen by default. You can take session.php from Laravel official repo.

Step - 4

Create framework session storage directory by

mkdir -p storage/framework/sessions

Thanks to DayDream

Step - 5

In bootstrap/app.php add bindings for \Illuminate\Session\SessionManager

$app->singleton(Illuminate\Session\SessionManager::class, function () use ($app) {
    return $app->loadComponent('session', Illuminate\Session\SessionServiceProvider::class, 'session');
});

$app->singleton('session.store', function () use ($app) {
    return $app->loadComponent('session', Illuminate\Session\SessionServiceProvider::class, 'session.store');
});

Thanks to @xxRockOnxx for finding loadComponent method. It takes 3 arguments,

  • first one is config file name. (file should be present in config/ directory)
  • second is ServiceProvider FQN
  • third is return of this method.

loadComponent just calls the $app->register and inject $app while building the ServiceProvider

How to Use

// Save Session
$router->get('/', function (\Illuminate\Http\Request $request) {

    $request->session()->put('name', 'Lumen-Session');

    return response()->json([
        'session.name' => $request->session()->get('name')
    ]);
});


// Test session
$router->get('/session', function (\Illuminate\Http\Request $request) {

    return response()->json([
        'session.name' => $request->session()->get('name'),
    ]);
});

How to use this example

You can clone this project using

git clone [email protected]:rummykhan/lumen-session-example.git 

cp .env.example .env

composer install

php  artisan serve

Contact

[email protected]

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].