[英]Method App\Http\Controllers\HomeController::home does not exist. [Laravel 8]
I was trying to register user using the Laravel Auth.我试图使用 Laravel Auth 注册用户。 First I got error with
App\\User
not found then I fix it with App\\Models\\User
it works.首先我在找不到
App\\User
遇到错误,然后我用App\\Models\\User
修复它,它可以工作。 I don't really know what with Laravel 8 becuase I never had a problem with user registration with previous version.我真的不知道 Laravel 8 是什么,因为我以前版本的用户注册从来没有问题。 Then I got this problem
然后我遇到了这个问题
BadMethodCallException Method App\\Http\\Controllers\\HomeController::home does not exist.
BadMethodCallException 方法 App\\Http\\Controllers\\HomeController::home 不存在。
I don't really know which code to provide since I don't even touch the default code of the Authentication/HomeController.我真的不知道要提供哪些代码,因为我什至没有触及 Authentication/HomeController 的默认代码。
But I did changed the namespace in RouteProvider但是我确实更改了 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');
}
}
试试Route::get('/home', [HomeController::class,'index']);
in your web.php
top you need to import在您的
web.php
顶部,您需要导入
use App\Http\Controllers\HomeController;
then u can use然后你可以使用
Route::get('/home', [HomeController::class,'index']);
Route::get('/home', 'HomeController@index')->name('home');
use this here no need to import在这里使用这个不需要导入
Note - your error is showing u don't have
home
method in your controller so createhome
method or change the correctmethod
by default it isindex
注意- 您的错误表明您的控制器中没有
home
方法,因此请创建home
方法或默认更改正确的method
,它是index
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.