PHP code example of overtrue / laravel-stateless-session

1. Go to this page and download the library: Download overtrue/laravel-stateless-session library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

overtrue / laravel-stateless-session example snippets


protected $middlewareGroups = [
        //...
        'api' => [
            \Overtrue\LaravelStatelessSession\Http\Middleware\SetSessionFromHeaders::class,
            \Illuminate\Session\Middleware\StartSession::class,
            'throttle:api',
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
        ],
    ];

    'header' => 'x-session',

axios.interceptors.request.use(function (config) {
    config.headers['x-session'] = 'session id from your localstorage';
    return config;
  }, function (error) {
    return Promise.reject(error);
  });

// Store the response session id
axios.interceptors.response.use(function (response) {
    if (response.headers['x-session']) {
        // store session id to localstorage
    }
    return response;
  }, function (error) {
    return Promise.reject(error);
  });