Reputation: 1
For all of my admin route i want to using separate file 'routes/admin.php', its working fine i can visit all the routes, but when i use middleware 'auth' and i visited admin routes its redirecting to my home page. but i still cannot visit my guest routes like '/sign-in, /sign-up' cause i am allready logged in,
Note: Wen i used 'routes/web.php' all of my middleware is working fine.
How can i solve this issue??
advance thanks to all!
routes/admin.php
<?php
use Illuminate\Support\Facades\Route;
Route::view('/dashboard', 'pages.backend.dashboard');
bootstrap.app.php
<?php
use App\Http\Middleware\AdminMiddleware;
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Illuminate\Support\Facades\Route;
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__ . '/../routes/web.php',
commands: __DIR__ . '/../routes/console.php',
health: '/up',
then: function () {
Route::middleware('auth')
->group(base_path('routes/admin.php'));
},
)
->withMiddleware(function (Middleware $middleware) {
$middleware->alias([
'admin' => AdminMiddleware::class,
]);
})
->withExceptions(function (Exceptions $exceptions) {
//
})->create();
Upvotes: 0
Views: 299
Reputation: 1
You forgot to include the 'web' middleware to your custom routes.This may cause this issue. Try including the 'web' middleware before 'auth' and then see if that solves your problem. The new route definition should look like this
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__ . '/../routes/web.php',
commands: __DIR__ . '/../routes/console.php',
health: '/up',
then: function () {
Route::middleware(['web','auth'])
->group(base_path('routes/admin.php'));
},
)
->withMiddleware(function (Middleware $middleware) {
$middleware->alias([
'admin' => AdminMiddleware::class,
]);
})
->withExceptions(function (Exceptions $exceptions) {`enter code here`
//
})->create();
Upvotes: 0