[英]Laravel 5.5 - Class Custom BaseController not found but exists
[英]Laravel Class BaseController not found
我是Laravel的新手。 因此,我在文件内部创建了TestController.php文件:
<?php
class TestController extends BaseController {
public function testFunction()
{
return "It works";
}
}
在航线上:
Route::get('test', 'TestController@testFunction');
我收到此错误:
TestController.php第2行中出现FatalErrorException:未找到类“ BaseController”
我正在使用laravel 5,我正在尝试从BaseController更改为Controller,但不起作用:(这里出了什么问题?
PS我尝试更改为“ \\ BaseController”。 不行
BaseController
中没有BaseController
这样的东西,请改用Controller
。 在整个框架中,在Controller
类中, BaseController
使用一次,但只能用作别名:
<?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;
}
您的控制器需要这样做:
<?php namespace App\Http\Controllers;
class TestController extends Controller
{
public function testFunction()
{
return "It works";
}
}
您的TestController是否在app / Http / Controllers中?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.