I'm newbie in laravel. So I've created TestController.php file, inside file:
<?php
class TestController extends BaseController {
public function testFunction()
{
return "It works";
}
}
In routes:
Route::get('test', 'TestController@testFunction');
I'm got this error:
FatalErrorException in TestController.php line 2: Class 'BaseController' not found
I'm using laravel 5, I'm trying to change from BaseController to Controller, not works :( What's wrong here? Thanks in advance :(
P.S I'm tried change to "\BaseController". Not works.
There is no such thing as a BaseController
in Laravel, use Controller
instead. BaseController
is used once throughout the framework, in the Controller
class, but only as a use as alias:
<?php
namespace App\Http\Controllers;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController; // <<< See here - no real class, only an alias
use Illuminate\Foundation\Validation\ValidatesRequests;
abstract class Controller extends BaseController
{
use DispatchesJobs, ValidatesRequests;
}
Your controller needs this:
<?php namespace App\Http\Controllers;
class TestController extends Controller
{
public function testFunction()
{
return "It works";
}
}
Is your TestController in app/Http/Controllers?