Laravel 5 - RouteCollection.php 第 143 行中的 NotFoundHttpException

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31648243/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 17:04:35  来源:igfitidea点击:

Laravel 5 - NotFoundHttpException in RouteCollection.php line 143

laravellaravel-5laravel-routing

提问by Chen Alon

I get this error:

我收到此错误:

Sorry, the page you are looking for could not be found.

1/1
NotFoundHttpException in RouteCollection.php line 143:
in RouteCollection.php line 143
at RouteCollection->match(object(Request)) in Router.php line 746
at Router->findRoute(object(Request)) in Router.php line 655
at Router->dispatchToRoute(object(Request)) in Router.php line 631
at Router->dispatch(object(Request)) in Kernel.php line 229
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 50
at VerifyCsrfToken->handle(object(Request), object(Closure))
at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 54
at ShareErrorsFromSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 62
at StartSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure))
at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 118
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 86
at Kernel->handle(object(Request)) in index.php line 64

I really don't understand what is the issue. I run the following commands:

我真的不明白这是什么问题。我运行以下命令:

composer dump-autoload
php artisan clear-compiled
php artisan route:clear

Nothing worked.

没有任何效果。

Laravel installation is under a subdirectory (public_html/ecodryer) and pointer to the public directory is configured by .htaccess:

Laravel 安装在一个子目录 (public_html/ecodryer) 下,指向 public 目录的指针由 .htaccess 配置:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^landings.yaza.co.il/ecodryer$ [NC,OR]
RewriteCond %{REQUEST_URI} !ecodryer/public/
RewriteRule (.*) /ecodryer/public/ [L]
</IfModule>

Route file:

路由文件:

<?php

Route::get('/', function () {
    return view('pages.site.main');
});

Any suggestions?

有什么建议?

Thanks ahead!

先谢谢了!

回答by davsp

This is an issue with your routes.php declaration, make sure you have defined a route for the url you are trying to access. For example:

这是您的 routes.php 声明的问题,请确保您已为您尝试访问的 url 定义了一个路由。例如:

Route::get('/', 'PageController@index');

You can find more detailed syntax on the Laravel website: http://laravel.com/docs/5.1/routing

你可以在 Laravel 网站上找到更详细的语法:http://laravel.com/docs/5.1/routing

Edit:

编辑:

Based on your routes.php - Change your Route to reflect as such:

根据您的 routes.php - 更改您的路线以反映如下:

Route::get('ecodryer', function () {
    return view('pages.site.main');
});

回答by Eranda

Sometimes this kind of problem comes with folder structure of the server such as url comes like localhost/project/. Try to create a virtual host for your local project. It's giving some extra benefits also. How to create a virtual host on wamp

有时这种问题与服务器的文件夹结构有关,例如 url 来自localhost/project/. 尝试为您的本地项目创建一个虚拟主机。它也提供了一些额外的好处。 如何在 wamp 上创建虚拟主机

回答by Varun Taliyan

For those who are getting similar error in laravel version 5.4.10(or 5.3 onwards as mentioned by @Chen Alon), routes.php file has been removed by default and if you still want to use it then just creating file is not enough. We need to include file in RouteServiceProvider.php file inside "map" function. Adding below line inside map function resolved the issue for me :

对于那些在 laravel 版本 5.4.10(或@Chen Alon 提到的 5.3 以后版本)中遇到类似错误的人,routes.php 文件已默认删除,如果您仍然想使用它,那么仅创建文件是不够的。我们需要在“map”函数中包含 RouteServiceProvider.php 文件中的文件。在 map 函数中添加以下行为我解决了这个问题:

require app_path('Http/routes.php');

回答by H.R.Taleghani

Sometimes this kind of problem comes with index.php. test your route by:

有时这种问题会出现在index.php 中。通过以下方式测试您的路线:

route/index.php

路线/index.php

or

或者

yourdomain/public/Route/index.php

yourdomain/public/Route/index.php

you can remove index.php from URL by config apache and virtual host. this linkcan help you.

您可以通过配置 apache 和虚拟主机从 URL 中删除 index.php。这个链接可以帮助你。

回答by Nagarjuna

Route::get('hello', 'Hello@index');

It should be under /projectname/routes/web.php

它应该在 /projectname/routes/web.php 下