简体   繁体   English

Laravel php 工匠“类请求不存在”

[英]Laravel php artisan "Class request does not exist"

I'm working with Laravel,我正在与 Laravel 合作,

suddenly when I try to run php artisan serve in my command prompt,突然,当我尝试在命令提示符下运行php artisan serve时,

it's displaying the error message:它显示错误消息:

In Container.php line 729: Class request does not exist

I have looked in all my controllers, models, and other files I could think of for loose Request references, but found nothing.我查看了我所有的控制器、模型和其他我能想到的松散请求引用文件,但一无所获。

How do I debug this?我该如何调试?

I was having this problem because a config file was calling the request helper function.我遇到这个问题是因为配置文件正在调用request助手 function。

Since I did not use this configuration when running my application from console, I just checked if the request was running from console before using the request helper.因为我在从控制台运行我的应用程序时没有使用这个配置,所以我只是在使用request助手之前检查请求是否从控制台运行。 For example,例如,

# my config file

return [
    'conf_key' => (app()->runningInConsole() === false) ? request()?->headers?->get('origin') : null,
// ...

Recheck your Controller class exists, because this error is thrown when there is some difference in Controller class name like重新检查您的控制器类是否存在,因为当控制器类名称存在一些差异时会引发此错误,例如

class PostController extends Controller { }

and

class Postcontroller extends Controller { }

Notice small "C"注意小“C”

In my case it was a problem with permission to bootstrap/cache on CI server.在我的情况下,在 CI 服务器上bootstrap/cache权限有问题。 Check this directory twice.检查此目录两次。

我在 bootstrap 目录中创建了一个缓存目录,我的问题解决了

I was using request() in config.php , and I don't know why this works until some day that crash with this error.我在config.php中使用request() ,我不知道为什么会这样,直到有一天因为这个错误而崩溃。 The site was working well, but composer/artisan commands fail.该站点运行良好,但 composer/artisan 命令失败。 I think it's normal, because there is no request... I handled checking isset($_SERVER["SERVER_NAME"]) , because I need the SERVER_NAME to config some parameters.我认为这是正常的,因为没有请求...我处理了检查isset($_SERVER["SERVER_NAME"]) ,因为我需要SERVER_NAME来配置一些参数。

I struggled with this issue for a while.我在这个问题上挣扎了一段时间。

Turns out, my issue was in a config file.原来,我的问题出在配置文件中。 One of my config classes was calling a static method with a bug in it.我的一个配置类调用了一个带有错误的静态方法。

The way I found it was to add echo statements in the following 2 files:我发现它的方法是在以下 2 个文件中添加 echo 语句:

vendor\/laravel\/framework\/src\/Illuminate\/Container.php<\/code>

To echo the classes the container is building.呼应容器正在构建的类。

/**
 * Instantiate a concrete instance of the given type.
 *
 * @param  string  $concrete
 * @return mixed
 *
 * @throws \Illuminate\Contracts\Container\BindingResolutionException
 */
public function build($concrete)
{
    // If the concrete type is actually a Closure, we will just execute it and
    // hand back the results of the functions, which allows functions to be
    // used as resolvers for more fine-tuned resolution of these objects.
    if ($concrete instanceof Closure) {
        return $concrete($this, $this->getLastParameterOverride());
    }

    echo 'Build - ' . $concrete . PHP_EOL;
    $reflector = new ReflectionClass($concrete);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “UserTableSeeder”类不存在 - Laravel 5.0 [php artisan db:seed] - Class 'UserTableSeeder' does not exist - Laravel 5.0 [php artisan db:seed] Laravel PHP Artisan类日志未找到 - Laravel php artisan class log does not find Laravel-php artisan config:cache-[ReflectionException]类cache.store不存在 - Laravel - php artisan config:cache - [ReflectionException] Class cache.store does not exist Laravel 7 - 工匠种子目标 class [DatabaseSeeder] 不存在 - Laravel 7 - artisan seed Target class [DatabaseSeeder] does not exist Laravel命令php artisan服务显示目录不存在 - Laravel command php artisan serve showing Directory does not exist Laravel (ver 6) php artisan route:list 在生产环境中返回“目标类不存在”错误(在本地环境中工作正常) - Laravel (ver 6) php artisan route:list return "Target class does not exist" error with production environment (worked fine in local environment) Laravel 7.0 php artisan route:list 返回“目标 class [App\Http\Controllers\API\RolesController]] 不存在。” - Laravel 7.0 php artisan route:list returns “Target class [App\Http\Controllers\API\RolesController]] does not exist.” 错误:laravel 5.5中不存在请求类 - Error: request class does not exist in laravel 5.5 Laravel请求类反射异常不存在 - Laravel Request Class Reflection Exception Does Not Exist Laravel PHP:存储库类不存在 - Laravel PHP: Repository Class does not exist
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM