Jamie
Jamie

Reputation: 10906

Laravel controllers not working

I'm learning laravel but it isn't working out that well.... I've set my route in routes.php:

Route::get('/','WelcomeController@index');

Then I obviously have made a controller called "WelcomeController" and it looks like this:

<?php
class WelcomeController extends BaseController
{
 public function index() 
 {
    return view ('index');
 }

}
?>

And then I've made a view called index with just some html text.

But when I go to localhost/public I receive the error:

FatalErrorException in WelcomeController.php line 3:
Class 'BaseController' not found

And when I say:

class WelcomeController extends Illuminate\Routing\Controller

It does not work!

What am I doing wrong.

Upvotes: 1

Views: 1053

Answers (2)

Mark
Mark

Reputation: 5787

Two suggestions:

  1. Run php composer dump-autoload to make sure the class mappings is fresh.

  2. Add use Controller; in your use block. The modify your controller to extend it. Example:

class WelcomeController extends Controller {...

Controller is an interface in Laravel 4.*

In Laravel 5 use instead: use App\Http\Controllers\Controller; according to the documentation here: http://laravel.com/docs/5.0/controllers

Upvotes: 0

cjds
cjds

Reputation: 8426

You should try

use Illuminate\Routing\Controller as BaseController;

at the top of your controller file. That acts as an import

Upvotes: 1

Related Questions