0

我试图使用 Laravel Auth 注册用户。首先我得到了App\User找不到的错误,然后我用它修复了App\Models\User它。我真的不知道 Laravel 8 的用途是什么,因为我在使用以前的版本注册用户时从来没有遇到过问题。然后我遇到了这个问题

BadMethodCallException 方法 App\Http\Controllers\HomeController::home 不存在。

我真的不知道要提供哪些代码,因为我什至没有触摸 Authentication/HomeController 的默认代码。

但我确实更改了 RouteProvider 中的命名空间

protected $namespace = 'App\Http\Controllers';

web.php

Route::get('/home', [HomeController::class,'home']);
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Contracts\Support\Renderable
     */
    public function index()
    {
        return view('home');
    }
}



在此处输入图像描述

4

2 回答 2

1

尝试Route::get('/home', [HomeController::class,'index']);

于 2020-09-11T04:53:22.563 回答
1

在您的web.php顶部,您需要导入

use App\Http\Controllers\HomeController;

然后你可以使用

Route::get('/home', [HomeController::class,'index']);

要不然

Route::get('/home', 'HomeController@index')->name('home');

在这里使用这个不需要导入

注意-您的错误显示您的控制器中没有方法,因此默认情况下home创建home方法或更改正确的方法是methodindex

于 2020-09-11T04:58:34.510 回答