Controller route not found in Laravel 4

Now I'm moving from L3 to L4. When registering the HomeController that comes with the default installation of L4, trying to go to www.domain.com/home gives me a ResourceNotFound exception. I did composer dumpautoload but that didn't help.

Am I missing an extra step?

routes.php

 Route::controller('home', 'HomeController'); 

Controllers /HomeController.php

 <?php class HomeController extends BaseController { public function showWelcome() { return View::make('hello'); } } 

Stacktrace Error

 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 
+2
source share
2 answers

According to the documentation :

Then just add the methods to the controller, with the HTTP verb prefix they respond to

So:

 class UserController extends BaseController { public function getIndex() { // Would response to /user and /user/index } } 

So, in your case, just rename showWelcome() to getWelcome() .

+4
source

Try changing the route:

 Route::resource('home', 'HomeController'); 

UPDATE: I feel bad, I thought you needed a resourceful controller, as described here: http://four.laravel.com/docs/controllers#resource-controllers

For "normal" RESTful controllers, juco's answer seems to be correct.

If you want to use basic controllers, you can use it to match your controller method:

 Route::get('home', ' HomeController@showWelcome '); 
+1
source

All Articles