[英]Laravel route not found when route exists
当我尝试访问我的 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 项目,一切都会按预期进行,所以它似乎是一个特定于项目的问题。
这是我的 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>
除非您编辑 RouteServiceProvider,否则这样的路线不起作用
laravel 有新版本,请确保您升级 PHP 或 XAMPP 并尝试更新 composer global laravel 并最后创建一个新的 laravel 项目。
请参阅 Laravel 文档和这篇文章https://youtu.be/MfE1tnMG6fE
您可以删除 name('home'),因为错误是 Route [home] not defined
<?php
// New Home Page for App
Route::get('/', 'Web\HomeController@index');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.