0
votes

laravel 5.8 hi I've added a new route file in routes directory with this name 'admin.php' session flash and errors validation don't work in this route file but in web.php session flash and errors of validation works well

this is map method in RouteServiceProvider

 public function map()
    {
        $this->mapApiRoutes();

        $this->mapWebRoutes();

        $this->mapAdminRoutes();
    }

mapAdminRoutes method

   protected function mapAdminRoutes()
    {
        Route::prefix('admin')->middleware(['auth','admin'])
            ->namespace($this->namespace."\Admin")
            ->group(base_path('routes/admin.php'));
    }

I don't use any middleware in admin.php routes

I Tried deleting ->middleware(['auth','admin']) in mapApiRoutes method

note:session flash and error validations of routes of admin.php work well in web.php

1

1 Answers

1
votes

You need to apply session middlewares for the new routes file in app/Http/Kernel.php

App\Http\Kernel

protected $middlewareGroups = [
    'admin' => [
        \Illuminate\Session\Middleware\StartSession::class,
        \Illuminate\View\Middleware\ShareErrorsFromSession::class,
    ],
];

I stripped out other middlewares and web and api for brevety, KEEP THEM

You can see that the web group applies the StartSession and the ShareErrorsFromSession middlewares, and so you must do that manually for the new routes file too

Hope this helps