Why are you disabling CSRF? Livewire updates themselves don't require CSRF, so unless you're completely defeating the purpose of Livewire components by having them manually post to a different route, there shouldn't be any need for what you're trying to do.
@dominikeller@learningraph@cherire Create a middleware that extends the VerifyCsrfToken (if L10 and lower) or go to bootstrap/app.php , in ->withMiddleware() section, do a $middleware->web(replace: ValidateCsrfToken => YourClass and in your custom Middleware override tokensMatch()
protected array $exceptPaths = [
'my-component'
];
/**
* Check if the CSRF tokens match for the given request.
*
* @param mixed $request
*
* @return bool True if the CSRF tokens match, false otherwise.
*/
protected function tokensMatch(mixed $request): bool
{
$componentPath = $this->getLivewireComponentPath($request);
foreach ($this->exceptPaths as $path) {
if (Str::is($path, $componentPath)) {
return true;
}
}
return parent::tokensMatch($request);
}
/**
* Get Livewire component path from the request.
*
* @param mixed $request
*
* @return string|null
*/
protected function getLivewireComponentPath(mixed $request): ?string
{
$components = $request->input('components')[0] ?? [];
$snapshot = json_decode($components['snapshot'] ?? '{}', true);
$memo = $snapshot['memo'] ?? [];
return $memo['name'] ?? null;
}