wire-extender icon indicating copy to clipboard operation
wire-extender copied to clipboard

Consider L11 slim skeleton in documentation

Open JulianGlueck opened this issue 1 year ago • 0 comments

First of all, your package is absolutely awesome for a lot of usecases! 🧨

One thing I noticed though is that it might be difficult for newcomers to follow the documentation as I assume it was written for Laravel 10. In 11, the middleware files are no longer in userland by default.

Perhaps it would be good to update the documentation for Laravel 11 and suggest to create a new custom "VerifyCsrfToken" middleware that simply extends the base middleware and applies your trait like so:

<?php

namespace App\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as FrameworkClass;
use WireElements\WireExtender\Http\Middlewares\IgnoreForWireExtender;

class VerifyCsrfToken extends FrameworkClass
{
    // Apply Wire Extender trait
    use IgnoreForWireExtender;
}

Then, the default middleware needs to be replaced during bootstrapping:

<?php

use App\Http\Middleware\VerifyCsrfToken as CustomVerifyCsrfToken;
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Illuminate\Foundation\Http\Middleware\ValidateCsrfToken;

return Application::configure(basePath: dirname(__DIR__))
    ->withRouting(
        web: __DIR__.'/../routes/web.php',
        commands: __DIR__.'/../routes/console.php',
        health: '/up',
    )
    ->withMiddleware(function (Middleware $middleware) {
        $middleware->web(replace: [
            ValidateCsrfToken::class => CustomVerifyCsrfToken::class,
        ]);
    })
    ->withExceptions(function (Exceptions $exceptions) {
        //
    })->create();

Maybe there's a better approach, but this did the job for us. 🙂

For Laravel 11 it would also be required to publish the CORS configuration file first:

php artisan config:publish cors

JulianGlueck avatar Apr 12 '24 15:04 JulianGlueck