【问题标题】:Call to undefined method Illuminate\Routing\Route::get()调用未定义的方法 Illuminate\Routing\Route::get()
【发布时间】:2023-03-23 20:40:01
【问题描述】:

我刚刚安装了 Laravel 5.1,访问了我的应用程序的主页,我收到以下错误:

哎呀,好像出了点问题。

1/1

routes.php 第 16 行中的 FatalErrorException:

调用未定义的方法 Illuminate\Routing\Route::get()

在 routes.php 第 16 行

这是我的 routes.php 文件:

<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/



Route::get('/', function () {
    return view('welcome');
});

【问题讨论】:

    标签: php laravel laravel-5 phpstorm laravel-routing


    【解决方案1】:

    这个导入错误:

    use Illuminate\Routing\Route;
    

    您实际上不必导入任何类,因为 Laravel 注册了一个全局别名 Route

    如果你想导入正确的类,那就是:

    use Illuminate\Support\Facades\Route;
    

    【讨论】:

    • 感谢您的回答,它成功了。但是,有点困惑,因为我没有导入该导入。如前所述,这是 Laravel 的全新安装。
    • 嗯。也许您的 IDE 做到了这一点。正如您在Github 上看到的那样,原始文件不包含这一行。
    • 是的,PHPStorm 似乎是罪魁祸首。我在创建项目时让它自动检测 PSR-0 命名空间根。
    • 或许你应该在 laravel 安装后使用命令行 composer dump-autoload。
    • @MaXi32 Composer 与此问题完全无关。
    【解决方案2】:

    对此发表评论:

    // use Symfony\Component\Routing\Route; 
    

    使用这个:

    use Illuminate\Support\Facades\Route; 
    

    【讨论】:

      【解决方案3】:

      Laravel VERSION = '5.2.30' 使用 zendserver enterprise

      在来自 zend 服务器的 C:\Program Files (x86)\Zend\ZendServer\data\plugins\laravel\zray\ZRay.php 上,更改第 193 行

      来自

      if (get_class($route) != 'Illuminate\Routing\Route') {
      

      if (get_class($route) != 'Illuminate\Support\Facades\Route') {   
      

      【讨论】:

        猜你喜欢
        • 2017-06-11
        • 1970-01-01
        • 2020-01-23
        • 1970-01-01
        • 2023-04-07
        • 2021-05-15
        • 1970-01-01
        • 2020-01-19
        • 2020-05-29
        相关资源
        最近更新 更多