【问题标题】:Laravel php artisan "Class request does not exist"Laravel php artisan“类请求不存在”
【发布时间】:2018-11-24 23:08:33
【问题描述】:

我正在使用 Laravel,

当我尝试在命令提示符中运行php artisan serve 时,突然,

它正在显示错误消息:

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

我查看了所有控制器、模型和其他我能想到的松散请求引用的文件,但一无所获。

我该如何调试?

【问题讨论】:

  • 再看一遍。还要确保您搜索方法参数
  • 发布完整的错误日志。
  • 我认为有些类不存在所以删除composer.lockvendor 目录,然后运行composer install 并再次测试。
  • 检查你的controller.php,你的操作中可能有Request引用public function index(Request $request),为此你需要导入use Illuminate\Http\Request;

标签: php laravel request laravel-artisan


【解决方案1】:

重新检查你的Controller类是否存在,因为当Controller类名有一些不同时会抛出这个错误

class PostController extends Controller { }

class Postcontroller extends Controller { }

注意小“C”

【讨论】:

    【解决方案2】:

    在我的情况下,CI 服务器上的bootstrap/cache 权限存在问题。检查此目录两次。

    【讨论】:

      【解决方案3】:

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

      【讨论】:

      • 答案应包含解决 OP 问题所需的确切代码。这是受欢迎的信息,但更适合作为评论保留。
      【解决方案4】:

      我在config.php 中使用了request(),但直到有一天,我不知道为什么它会因为这个错误而崩溃。该站点运行良好,但作曲家/工匠命令失败。我觉得很正常,因为没有请求……我处理了检查isset($_SERVER["SERVER_NAME"]),因为我需要SERVER_NAME来配置一些参数。

      【讨论】:

      【解决方案5】:

      我在这个问题上挣扎了一段时间。

      原来,我的问题出在配置文件中。我的一个配置类调用了一个带有错误的静态方法。

      我发现的方法是在以下2个文件中添加echo语句:

      vendor/laravel/framework/src/Illuminate/Container.php

      回显容器正在构建的类。

      /**
       * 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);
      

      这里。

      vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/LoadConfiguratio n.php

      回显正在加载的配置类。

      /**
       * Load the configuration items from all of the files.
       *
       * @param  \Illuminate\Contracts\Foundation\Application  $app
       * @param  \Illuminate\Contracts\Config\Repository  $repository
       * @return void
       * @throws \Exception
       */
      protected function loadConfigurationFiles(Application $app, RepositoryContract $repository)
      {
          $files = $this->getConfigurationFiles($app);
      
          if (! isset($files['app'])) {
              throw new Exception('Unable to load the "app" configuration file.');
          }
      
          foreach ($files as $key => $path) {
              echo 'config - ' .$key . PHP_EOL;
              $repository->set($key, require $path);
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2018-02-16
        • 2016-07-12
        • 2021-03-04
        • 2017-09-23
        • 2020-06-20
        • 2020-06-09
        • 1970-01-01
        • 2020-01-11
        • 2021-05-22
        相关资源
        最近更新 更多