3
votes

I'm looking to create a route group that enables particular users to view information on my site without being authenticated.

At the moment, i've created a route service provider called 'public' as follows:

Route::get('customer/application', function () {
    return view('customerview.customer-application');
});

When I write 'php artisan route:list' the following comes up for the route:

Method: GET | HEAD URL: customer/application Middleware: ''

I have removed all middleware in an attempt to bypass auth, but with no luck.

The area which is redirecting me to the login page is here in App\Exceptions\Handler.php:

protected function unauthenticated($request, AuthenticationException $exception)
{
    if ($request->expectsJson()) {
        return response()->json(['error' => 'Unauthenticated.'], 401);
    }
    return redirect()->guest('login');
}

I also tried assigning the route to 'guest' group but no help. How can I bypass the return redirect()->guest('login'); for different groups?

1
Can you provide you're route file ? because if you don't apply middleware or auth check on any group it will be visible to unauthenticated users, i'm assuming you've put Auth::routes() outside of any group in route file. - Vipertecpro
check you RouteServiceProvider.php may be you add Middleware there. - Md. Miraj Khan
Are you calling Route::auth() before you are defining this route? - levi

1 Answers

0
votes

Rookie mistake - I had a route with customer/{id} so I changed my new route to open/customer/application instead.

But for anyone wondering how to make a route outside of the scope of auth?

In RouteServiceProvider.php I created a mapping for the 'public' routes to enable me to create a new file with all my routes as so:

protected function mapPublicRoutes()
{
    Route::group([
        'namespace' => $this->namespace,
    ], function ($router) {
        require base_path('routes/public.php');
    });
}

In routes/public.php i added the following:

Route::get('open/customer/application', function () {
    return view('customerview.customer-application');
});

Route::auth(); is still in my web.php file at the end without any problems / collision.

I hope my mistake will educate others to check their route files before bothering the Stackexchage community :')