NotFoundHttpException in RouteCollection.php line

2019-01-20 18:19发布

问题:

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



标签: laravel-5.1