Skip to content

Instantly share code, notes, and snippets.

@RikoDEV
Last active September 8, 2023 13:27
Show Gist options
  • Save RikoDEV/c77de926c8793d3e59b738572b4be227 to your computer and use it in GitHub Desktop.
Save RikoDEV/c77de926c8793d3e59b738572b4be227 to your computer and use it in GitHub Desktop.
Fix Livewire v3 unknown route after caching (mcamara/laravel-localization)

Livewire v3 x Laravel Localization

1. Create new file called HandleRequests.php inside app\Livewire directory.

<?php

namespace App\Livewire;

class HandleRequests extends \Livewire\Mechanisms\HandleRequests\HandleRequests
{
    function getUpdateUri()
    {
        return (string) str(route('livewire.update', null, false))->start('/');
    }
}

2. Add this line to AppServiceProvider register function.

    /**
     * Register any application services.
     */
    public function register(): void
    {
        ...
        $this->app->bind(\Livewire\Mechanisms\HandleRequests\HandleRequests::class, \App\Livewire\HandleRequests::class);
    }
  1. Edit composer.json
    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/"
        },
        ...
        "exclude-from-classmap": [
            "vendor\\livewire\\livewire\\src\\Mechanisms\\HandleRequests\\HandleRequests.php"
        ]
    },

Done. Now php artisan route:trans:cache should work fine with Livewire v3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment