如何从Laravel应用程序中删除laravel_session cookie? [英] How to get rid of laravel_session cookie from Laravel application?
问题描述
我正试图摆脱laravel_session.
I'm trying to get rid of laravel_session.
我尝试为其创建中间件
更改驱动程序以使用:array
file
,database
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 :
url1
或url2
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屋!