Laravel How to solve the phenomenon that you can see it by directly inserting the URL even if you are not logged in (Middleware)

Aug 24, 2020 PHP Laravel middleware

In order not to display the article posting screen to unlogged-in users,

If you are not logged in but just add middleware to the above,

You will be taken to the login screen.

└── laravel
    └── app
        └── Http
            └── Middleware
     └── Authenticate.php


namespace App\Http\Middleware;

use Illuminate\Auth\Middleware\Authenticate as Middleware;

class Authenticate extends Middleware
     * Get the path the user should be redirected to when they are not authenticated.
     * @param \Illuminate\Http\Request $request
     * @return string
    protected function redirectTo($request)
        if (! $request->expectsJson()) {
            return route('login');

You can arrange where the transition is made by playing with login.

That’s all: relaxed: