1
votes

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.

2
Looks to me like you missed to declare the namespace your controller is in. At least if you follow the default structure that is. Add namespace App\Http\Controllers; at the top of your file.lukasgeiter
thankyou it works now. But when I add another route "Contact" it's not found in localhost/public/contact ? But I'm doing it exactly the same?Jamie
Try localhost/public/index.php/contact. If that works, you have a htaccess problem...lukasgeiter
THANKSS, That works. But how Can I fix the htacces problem?Jamie
Make sure htaccess is enabled. (AllowOverride All) I'm sure you'll find something on google if you need more help with that...lukasgeiter

2 Answers

1
votes

You should try

use Illuminate\Routing\Controller as BaseController;

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

0
votes

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