wire-elements / wire-extender

Wire Extender allows you to embed any Livewire component on any website or even within a static HTML file.
https://wire-elements.dev/blog/embed-livewire-components-using-wire-extender
MIT License
237 stars 8 forks source link

Consider L11 slim skeleton in documentation #7

Closed JGlueck-WIKA closed 3 months ago

JGlueck-WIKA commented 5 months ago

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
JGlueck-WIKA commented 3 months ago

@PhiloNL, in case you might consider to move the documentation into this (or a separate) repository, I'd be happy to create a PR for this. 🙂

PhiloNL commented 3 months ago

Thanks @JGlueck-WIKA 😄 I've updated the documentation on the website 🙌