A route with optional parameter works when doing like this:
Route::get('{anything}',function($anything){echo $anything;});
but I would like to use a controller. Doing like this produces an error:
Route::get('{anything}','redirectController');
controller:
class redirectController {
public function index($anything){
echo $anything;
}}
What may be the problem? (using laravel 4.2)
update: I renamed the controller with capital letter, and tried this:
Route::get('{anything}',['uses' => 'RedirectController@index']);
but it's still an error: "Call to undefined method RedirectController::getAfterFilters() ".
If you want to use a controller there're two options:
Route::controller('route', 'SomeController');
Route::get('route', ['uses' => 'SomeController@index']);
;In the first case you have to read this:
http://laravel.com/docs/4.2/controllers#implicit-controllers
Name of your action in this case should be
getIndex
, not justindex
.Good luck!
UPD
Make sure your controller extends Laravel's Controller class like follows: