如何从Laravel应用程序中删除laravel_session cookie? [英] How to get rid of laravel_session cookie from Laravel application?

查看:182
本文介绍了如何从Laravel应用程序中删除laravel_session cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图摆脱laravel_session.

I'm trying to get rid of laravel_session.

我尝试为其创建中间件

https://laracasts.com/discuss/channels/laravel/laravel-51-disable-session-and-cookies-for-some-routes

更改驱动程序以使用:array filedatabase

Change the driver to use : array file, database

这些都不起作用.每次刷新时,我总是会看到以下内容:

None of that works. Every time I refresh, I always see this:

我该如何实现?甚至有可能做到吗?

How can I achieve this? Is it even possible to do ?

推荐答案

如果我有不希望Laravel使用laravel_session的特定路由. 您可以将其应用于所需的任何路线.

If I have specific routes that I don't want Laravel to use laravel_session. You can apply that to any routes you want.

例如例如,如果您只想应用这两条路线:

Ex. For example, if you want to apply to only these 2 routes :

url1url2

Route::get('/url1', 'SampleController@fnName');

Route::get('/url2', 'SampleController@fnName2');

创建/app/Http/Middleware/StartSessionMiddleware.php

<?php
namespace App\Http\Middleware;

use Closure;
use Config;

use Illuminate\Session\Middleware\StartSession as BaseStartSession;

class StartSessionMiddleware extends BaseStartSession
{

    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next) {

        if($request->is('url1') || $request->is('url2')) {
            Config::set('session.driver', 'array');
        }

        return parent::handle($request, $next);
    }
}

通过在/app/Http/Kernel.php

\App\Http\Middleware\StartSessionMiddleware::class,

现在,那两条路线不再需要laravel_session.

and now, that laravel_session should not be there anymore for those 2 routes.

我希望这可以帮助某人.

I hope this can help someone.

这篇关于如何从Laravel应用程序中删除laravel_session cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆