NotFoundHttpException in RouteCollection.php line 161 in laravel

冷暖自知 提交于 2019-12-29 01:58:06

问题


I added the following routes in routes.php:

Route::get('/', function () {
    return 'Hello World';
});

Route::get('user/{id}', function ($id) {
    return 'User '.$id;
});

Route::post('foo/bar', function () {
    return 'Hello World';
});

Route::put('foo/bar', function () {
 //
});

Route::delete('foo/bar', function () {
   //
});

And I am getting this error when I browse to /laravel/user/5/

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

NotFoundHttpException in RouteCollection.php line 161:1) in RouteCollection.php line 161.2) at RouteCollection-match(object(Request)) in Router.php line 533 at Router-findRoute(object(Request)) in Router.php line 512.

and a bunch of other errors.

Is anything wrong in my route configuration?


回答1:


This problem is because when installed laravel through command promot i ran "composer create-project laravel/laravel –-prefer-dist" as the document suggest.

so actually correct command is "composer create-project laravel/laravel yourProjectName"




回答2:


my problem was in the virtual server definition where I have defined in the laravel folder as document root in the apache virtual server setup file,

I was getting the error while accessing

localhost:9000/laravel/api/courselist

once I changed it to

 localhost:9000/api/courselist

I started getting the proper response



来源:https://stackoverflow.com/questions/42412909/notfoundhttpexception-in-routecollection-php-line-161-in-laravel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!