admin 管理员组文章数量: 1086019
I'm building an application which has a public facing "landing page" that is rendered using data from the database.
To do so I'd like to use Laravel Folio (running on Laravel 12). I noticed that even though it's not needed, Laravel will set session and XSRF cookies in responses from the public part of the application. I would like to remove these.
My FolioServiceProvider
does not define any middleware:
public function boot(): void
{
Folio::path(resource_path('views/pages'))->middleware([
'*' => [
//
],
])->uri('/');
}
and I don't edit anything in bootstrap/app.php
:
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
commands: __DIR__.'/../routes/console.php',
web: __DIR__.'/../routes/web.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
//
})
->withExceptions(function (Exceptions $exceptions) {
//
})->create();
Searching the web, I found advice on removing StartSession
middleware from the middleware stack, however when I do that:
$middleware->remove([
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\Illuminate\Foundation\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Session\Middleware\StartSession::class,
]);
a 500 error complaining about how there is no session is raised:
Session store not set on request.
which seems to originate in the (previously removed?) VerifyCsrfToken
middleware trying to access the request's session.
I have a hard time understanding how middleware is being stacked in this combo, especially since this is my first time using Folio and Laravel version 12 (middleware defintion worked differently before).
Ideally, I'd like to come to a point where everything routed through Folio does not pass any middleware, but removing sessions would be a good start also.
I'm building an application which has a public facing "landing page" that is rendered using data from the database.
To do so I'd like to use Laravel Folio (running on Laravel 12). I noticed that even though it's not needed, Laravel will set session and XSRF cookies in responses from the public part of the application. I would like to remove these.
My FolioServiceProvider
does not define any middleware:
public function boot(): void
{
Folio::path(resource_path('views/pages'))->middleware([
'*' => [
//
],
])->uri('/');
}
and I don't edit anything in bootstrap/app.php
:
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
commands: __DIR__.'/../routes/console.php',
web: __DIR__.'/../routes/web.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
//
})
->withExceptions(function (Exceptions $exceptions) {
//
})->create();
Searching the web, I found advice on removing StartSession
middleware from the middleware stack, however when I do that:
$middleware->remove([
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\Illuminate\Foundation\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Session\Middleware\StartSession::class,
]);
a 500 error complaining about how there is no session is raised:
Session store not set on request.
which seems to originate in the (previously removed?) VerifyCsrfToken
middleware trying to access the request's session.
I have a hard time understanding how middleware is being stacked in this combo, especially since this is my first time using Folio and Laravel version 12 (middleware defintion worked differently before).
Ideally, I'd like to come to a point where everything routed through Folio does not pass any middleware, but removing sessions would be a good start also.
Share Improve this question asked Mar 27 at 21:04 m90m90 11.8k15 gold badges67 silver badges119 bronze badges1 Answer
Reset to default 0You can create a middleware to set the session into the array driver like this.
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Config;
use Laravel\Folio\Folio;
public function boot(): void
{
Folio::path(resource_path('views/pages'))->middleware([
'*' => [
function (Request $request, Closure $next) {
Config::set('session.driver', 'array');
return $next($request);
},
],
])->uri('/');
}
When you set the session.driver
to array
, the session will not be persisted as mentioned here in the laravel docs.
This will skip saving the session into your storage/framework/session
directory, or into your sessions
table (depending on your SESSION_DRIVER
environment) which will free up your storage space.
Hopefully this helps.
本文标签: phpHow do I disable sessionsmiddleware for Laravel FolioStack Overflow
版权声明:本文标题:php - How do I disable sessionsmiddleware for Laravel Folio - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744067769a2527921.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论