thedevdojo / voyager

Voyager - The Missing Laravel Admin
https://voyager.devdojo.com
MIT License
11.78k stars 2.67k forks source link

Voyager says that route <route.name> not defined after create bread #5092

Closed cloudberrystory closed 4 years ago

cloudberrystory commented 4 years ago

Description

After create any bread i usually see exception like "route not defined". I use php artisan route:cache or optimize to cache my routes and if i call this command after create bread - error fixes. This error reproduces because laravel dont know any new voyager routes until their not cached.

Steps To Fix

  1. Create listener in App\Listeners with method handle()
    
    namespace App\Listeners;

use Illuminate\Support\Facades\Artisan;

class RouteCacheListener {

public function handle() {
    Artisan::call('route:cache');
}

}

2. Add this listener to your app/Providers/EventServiceProvider.php on TCG\Voyager\Events\BreadAdded
    BreadAdded::class => [
        RouteCacheListener::class,
    ]


## Steps To Reproduce
Steps to reproduce the behavior:
1. Go to '/bread'
2. Click on any table
3. Save bread
4. See error
emptynick commented 4 years ago

Definitely not a bug. Of course Laravel only knows about the routes in cache when you cache them. You shouldn't cache your routes when developing.

MrCrayon commented 4 years ago

As @emptynick said you are not supposed to create BREADs in production and you are not supposed to cache routes on development, so something is not right in your workflow but thanks for the suggestion.

Also please remember when you are opening an issue to fill required information.

<!-- The following information is required for bug reports.  Issues without it will be closed without response --->
 - Laravel: v#.#.#
 - Voyager: v#.#.#
 - PHP: #.#
 - Database: [type] [version] (e.g. MySQL 8.0)
cloudberrystory commented 4 years ago

Thanks for replies. Maybe it is not right way to create BREADs in production and i need to revise my workflow. But i just want to share my solution for people who gets same problem with route caching.

github-actions[bot] commented 3 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. If you have further questions please ask in our Slack group.