问题
I am in the process of migrating from L3 to L4. When registering the HomeController
controller that came with the default L4 installation, trying to go to the page www.domain.com/home
gives me a ResourceNotFound
exception. I did a composer dumpautoload
but that did not help.
Did I miss out an additional step?
routes.php
Route::controller('home', 'HomeController');
controllers/HomeController.php
<?php
class HomeController extends BaseController {
public function showWelcome()
{
return View::make('hello');
}
}
Error Stacktrace
NotFoundHttpException:
in /var/www/l4/vendor/laravel/framework/src/Illuminate/Routing/Router.php line 1338
at Router->handleRoutingException(object(ResourceNotFoundException)) in /var/www/l4/vendor/laravel/framework/src/Illuminate/Routing/Router.php line 992
at Router->findRoute(object(Request)) in /var/www/l4/vendor/laravel/framework/src/Illuminate/Routing/Router.php line 956
at Router->dispatch(object(Request)) in /var/www/l4/vendor/laravel/framework/src/Illuminate/Foundation/Application.php line 463
at Application->dispatch(object(Request)) in /var/www/l4/vendor/laravel/framework/src/Illuminate/Foundation/Application.php line 448
at Application->run() in /var/www/l4/public/index.php line 51
回答1:
As per the documentation:
Next, just add methods to your controller, prefixed with the HTTP verb they respond to
So:
class UserController extends BaseController {
public function getIndex()
{
// Would response to /user and /user/index
}
}
So, in your case simply renaming showWelcome()
to getWelcome()
should suffice.
回答2:
Try changing your route to this:
Route::resource('home', 'HomeController');
UPDATE: My bad, I thought you wanted a resourceful controller, as described here: http://four.laravel.com/docs/controllers#resource-controllers
For "normal" RESTful controllers juco's answer seems right.
If you want basic controllers, you can use this to correspond to your controller method:
Route::get('home', 'HomeController@showWelcome');
来源:https://stackoverflow.com/questions/15588409/controller-route-not-found-in-laravel-4