Laravel 未找到使用中间件重定向到命名路由的页面

Laravel 未找到使用中间件重定向到命名路由的页面,laravel,Laravel,我的web.php文件中有以下路径: Route::get('/', 'PostsController@index')->name('home'); Route::get('/login', 'SessionsController@show'); SessionController类有一个公共构造函数,该构造函数使用Laravel的中间件检查用户是否是来宾: namespace App\Http\Controllers; use Illuminate\Http\Request; cla

我的web.php文件中有以下路径:

Route::get('/', 'PostsController@index')->name('home');
Route::get('/login', 'SessionsController@show');
SessionController类有一个公共构造函数,该构造函数使用Laravel的中间件检查用户是否是来宾:

namespace App\Http\Controllers;
use Illuminate\Http\Request;

class SessionsController extends Controller
{
    public function __construct() {
        $this->middleware('guest')->except(['destroy']);

    public function create() {

        // Validade form data
        $this->validate(request(), [
            'email' => 'required',
            'password' => 'required'
        ]);

        // Attempt to authenticate the user
        if(! auth()->attempt(request(['email', 'password']))) {
            return back()->withErrors([
                'message' => 'Please check you credentials and try again'
            ]);
        }
        return redirect()->home();
    }
    public function show() {
        return view('login.show');
    }

    public function destroy() {
        auth()->logout();
        return redirect()->home();
        //return redirect()->route('home');
    }
}
发生的情况是,当我登录并尝试访问
/login
时,我被重定向到
主页
,但我在浏览器中看到“对不起,找不到页面”。我知道中间件会在我尝试登录时检查我是否是客人,如果我不是,它会将我重定向到推荐页面

我检查了
php artisan route:list
,我可以看到
/
被分配了名称
home
。我现在没有主意了,我会感谢你的帮助。

试试这个

return redirect()->route('home');

你的PostsController有一个索引方法,对吗?@mattQuest是的,我有。虽然你只提到了这个片段,但我认为它不会有任何影响,因为这个问题与构造函数有关,中间件将处理重定向的页面。谢谢你的关注。