0
votes

I'm new to Laravel, I have a route in my routes.php file like this:

    <?php
Route::resource('search', 'SearchController');                
?>

and I have the controller app/controllers/SearchController.php that looks like this:

<?php

    class SearchController extends \BaseController {

        protected $layout = 'layouts.master';
        public function create() {}

        public function store(){}

        public function index(){
            return View::make('hello');
        }
    }
    ?>

I previously had a controller with unrestful methods name SearchController. I renamed that one to OldSearchController and updated the routes.

and a file hello.php in app/views.

but, whenever I try to access the page via http://localhost/search, I get the following error:

BadMethodCallException 
Method [index] does not exist.

what else needs to be done?

2
Is that all you have on the app/routes.php file? - vsmoraes
yes, just the single route - Chris Drappier
Let's try something more simple: Route::get('/search', function() { return 'It works!'; });. You have mod_rewrite working, right? - vsmoraes
so, I can make a controller, FooController with a corresponding route and the same logic and it works. Is SearchController defined by default in Laravel possibly? if so, where would it be? - Chris Drappier
I just tested your route and controller on a fresh installation of Laravel 4 and it worked like a charm. I'm searching something else that can be causing this problem - vsmoraes

2 Answers

2
votes

All you need to do is run this:

composer dump-autoload

Your classes are being cached and there is likely a conflict going on with your previous SearchController.

1
votes

As I said in the comments, the following command did the trick:

php artisan dump-autoload

Probably something happened during the installation.