【问题标题】:Laravel route not found when route exists路线存在时找不到Laravel路线
【发布时间】:2020-11-17 02:26:20
【问题描述】:

当我尝试访问我的 laravel 站点时,我在控制台中收到此错误。

Laravel development server started: <http://127.0.0.1:8000>
[Mon Nov 16 10:39:15 2020] PHP Fatal error:  Uncaught InvalidArgumentException: Route [home] not defined. in /Users/threeaccents/code/src/gitlab.com/few/bodylove/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php:389
Stack trace:
#0 /Users/threeaccents/code/src/gitlab.com/few/bodylove/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php(822): Illuminate\Routing\UrlGenerator->route('home', Array, true)
#1 /Users/threeaccents/code/src/gitlab.com/few/bodylove/storage/framework/views/e071ac62e490c49233841ae8b6b3906075bc0187.php(6): route('home')
#2 /Users/threeaccents/code/src/gitlab.com/few/bodylove/vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php(43): include('/Users/threeacc...')
#3 /Users/threeaccents/code/src/gitlab.com/few/bodylove/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php(59): Illuminate\View\Engines\PhpEngine->evaluatePath('/Users/threeacc...', Array)
#4 /Users/threeaccents/code/src/gitlab.com/few/bodylove/vendor/laravel/framework/src/Illuminate/View/View.php(142): Illuminate\Vi in /Users/threeaccents/code/src/gitlab.com/few/bodylove/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php on line 389
[Mon Nov 16 10:39:15 2020] PHP Fatal error:  Uncaught InvalidArgumentException: Route [home] not defined. in /Users/threeaccents/code/src/gitlab.com/few/bodylove/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php:389
Stack trace:
#0 /Users/threeaccents/code/src/gitlab.com/few/bodylove/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php(822): Illuminate\Routing\UrlGenerator->route('home', Array, true)
#1 /Users/threeaccents/code/src/gitlab.com/few/bodylove/storage/framework/views/e071ac62e490c49233841ae8b6b3906075bc0187.php(6): route('home')
#2 /Users/threeaccents/code/src/gitlab.com/few/bodylove/vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php(43): include('/Users/threeacc...')
#3 /Users/threeaccents/code/src/gitlab.com/few/bodylove/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php(59): Illuminate\View\Engines\PhpEngine->evaluatePath('/Users/threeacc...', Array)
#4 /Users/threeaccents/code/src/gitlab.com/few/bodylove/vendor/laravel/framework/src/Illuminate/View/View.php(142): Illuminate\Vi in /Users/threeaccents/code/src/gitlab.com/few/bodylove/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php on line 389

但是回家的路线是明确定义的。我什至将它设置在我的路由文件的顶部,以确保没有其他东西覆盖它。

routes/web.php
<?php

// New Home Page for App
Route::get('/', 'Web\HomeController@index')->name('home');

...

php artisan route:list

+--------+----------------------------------------+--------------------------------------------------------------------------------------------+--------------------------------------------+------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Domain | Method                                 | URI                                                                                        | Name                                       | Action                                                                                         | Middleware                                                                                                                                                                        |
+--------+----------------------------------------+--------------------------------------------------------------------------------------------+--------------------------------------------+------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|        | GET|HEAD                               | .well-known/apple-developer-merchantid-domain-association                                  |                                            | App\Http\Controllers\Web\ApplePayDomainVerificationController                                  | web                                                                                                                                                                               |
|        | GET|HEAD                               | /                                                                                          | home                                       | App\Http\Controllers\Web\HomeController@index                                                  | web                                                                                                                                                                               |

更新

我已经清除了路由缓存,删除了供应商文件夹,重新安装了 PHP,但似乎没有任何解决问题的方法。

我已经在我的工作笔记本电脑上尝试过(相同的设置),一切正常。这似乎是我当前电台的问题,但我不确定是什么原因造成的。我在 mac os 10.14.4 上使用 PHP 7.2。 Laravel 5.7

我还认为这可能是一个整体系统问题,但如果我创建一个新的 laravel 项目,一切都会按预期工作,所以它似乎是一个项目特定的问题。

【问题讨论】:

  • 关于你的控制器文件夹结构?
  • 这能回答你的问题吗? 404 Not Found, but route exist in Laravel 5.4
  • 非常有趣.. 你使用 opcache 吗?或任何其他 php 级别的缓存系统?我建议您完全rm -rf 删除生成的缓存文件夹。也许它只是搞砸了,无法覆盖它..
  • 尝试使用url("/") 代替路由助手来确定行为。

标签: php laravel laravel-5


【解决方案1】:

这是我的 apache 配置的问题。似乎在我最新的 brew update apache 上得到了更新,并且配置文件发生了一些变化。我不得不改变

#
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other 
# <Directory> blocks below.
#
<Directory />
    AllowOverride none
    Require all denied
</Directory>

<Directory />
    AllowOverride all
    Require all granted
</Directory>

【讨论】:

    【解决方案2】:

    除非您编辑 RouteServiceProvider,否则这样的路由不起作用

    有新版本的laravel,请确保你升级你的PHP或XAMPP并尝试更新作曲家全局laravel并最后创建一个新的laravel项目。

    查看 Laravel 文档 还有这个帖子 https://youtu.be/MfE1tnMG6fE

    【讨论】:

      【解决方案3】:

      你可以删除name('home'),因为错误是Route [home] not defined

      <?php
      // New Home Page for App
      Route::get('/', 'Web\HomeController@index');
      

      【讨论】:

        猜你喜欢
        • 2016-09-16
        • 2019-01-30
        • 2018-12-09
        • 2020-04-05
        • 1970-01-01
        • 2021-01-06
        • 2015-09-08
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多