user1072337
user1072337

Reputation: 12945

NotFoundHttpException for Controller route in Laravel 4

I am trying to get started using controllers in Laravel 4 and I am running into some trouble. Here is the basic run down:

I have a controller in the controllers folder called FansController in the file FansController.php:

<php

class FansController extends BaseController {

        public $restful = true

        public function getindex() {
        return View::make('fans.landing');
    }
}

Within my views folder, I have a folder called "fans" that controls a view file "landing.blade.php". It contains simple html: <h1>hello</h1>

In my routes.php file, I have a route calling the controller. Here is that code:

Route::get('landing', array('uses' => 'FansController@index'));

When I visit the url: public/fans/landing

I receive a "NotFoundHttpException";

Do you have any ideas what may be going wrong? Thank you for your help.

Upvotes: 1

Views: 4291

Answers (2)

Neo
Neo

Reputation: 886

First off you need to specify what version of Laravel you are running.

If you are running Laravel 4 then:

// routes.php
Route::get('/', array('uses' => 'GuestController@getIndex'));

// GuestController.php
class GuestController extends BaseController {
    public function getIndex() {
         return 'Hello world.';
    }
}

Then run $ composer dump-autoload -o or php composer.phar dump-autoload -o (if your composer is installed locally) on your CLI

In laravel 3, however

// routes.php
Route::get('/', array('uses' => 'GuestController@index'));

// GuestController.php
class GuestController extends BaseController {
    public $restful = true;
    public function get_index() {
         return 'Hello world.';
    }
}

Upvotes: 4

Antonio Carlos Ribeiro
Antonio Carlos Ribeiro

Reputation: 87719

Probably you need to change your method name to index:

class FansController extends BaseController {

    public $restful = true

    public function index() {
        return View::make('fans.landing');
    }

}

Upvotes: 0

Related Questions