简体   繁体   English

找不到Laravel类BaseController

[英]Laravel Class BaseController not found

I'm newbie in laravel. 我是Laravel的新手。 So I've created TestController.php file, inside file: 因此,我在文件内部创建了TestController.php文件:

<?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 TestController.php第2行中出现FatalErrorException:未找到类“ BaseController”

I'm using laravel 5, I'm trying to change from BaseController to Controller, not works :( What's wrong here? Thanks in advance :( 我正在使用laravel 5,我正在尝试从BaseController更改为Controller,但不起作用:(这里出了什么问题?

PS I'm tried change to "\\BaseController". PS我尝试更改为“ \\ BaseController”。 Not works. 不行

There is no such thing as a BaseController in Laravel, use Controller instead. BaseController中没有BaseController这样的东西,请改用Controller BaseController is used once throughout the framework, in the Controller class, but only as a use as alias: 在整个框架中,在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;
}

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? 您的TestController是否在app / Http / Controllers中?

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM