gpt4 book ai didi

php - 类不存在 - Laravel

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:04:46 27 4
gpt4 key购买 nike

我正在关注 this tutorial .我目前使用的是 laravel 5.3,所以它有点过时了。我已经按照教程一步一步完成了,但是,我得到了

   ReflectionException in Container.php line 749:
Class First does not exist

in Container.php line 749
at ReflectionClass->__construct('First') in Container.php line 749
at Container->build('First', array()) in Container.php line 644
at Container->make('First', array()) in Application.php line 709
at Application->make('First') in Kernel.php line 173
at Kernel->terminate(object(Request), object(Response)) in index.php line 58
at require_once('C:\xampp5\htdocs\laravel\laravel\public\index.php') in server.php line 21

一切都和教程中一样。我不知道问题出在哪里。

最佳答案

问题是您创建了一个 FirstMiddleware 但您在这里仅将其称为 First:

<?php
Route::get('/usercontroller/path',[
'middleware' => 'First',
'uses' => 'UserController@showPath'
]);

如官方文档所述,

if you would like to assign middleware to specific routes, you should first assign the middleware a key in your app/Http/Kernel.php

因此,将此添加到您的 app/Http/Kernel.php 文件中:

protected $routeMiddleware = [
// the other route middlewares are defined here
'First' => \App\Http\Middleware\FirstMiddleware::class, // add this line
]

我认为这应该足够了。

关于php - 类不存在 - Laravel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39871276/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com