laravel 5 models Class not found

I have a question with model in laravel 5

I want to access my model and get return value. but that not work :(

app/Http/Controllers/MemberController.php

namespace AppHttpControllers;

use IlluminateHttpRequest;

use AppHttpRequests;
use AppHttpControllersController;

use AppModel;
class MemberController extends Controller
{
    public function index()
    {
        return MemberModel::test();
    }
} 

app/Model/MemberModel.php

namespace AppModel;

use IlluminateDatabaseEloquentModel;

class MemberModel extends Model
{
    public function test(){
        return "123";
    }
}

routes.php

Route::get('test', 'MemberController@index');

and error message is ..

FatalErrorException in MemberController.php :
Class 'AppHttpControllersMemberModel' not found

您将模型保存在Model文件夹中,因此它应该是

use AppModelMemberModel;

有2个选项,你需要使用命名空间,否则使用这种方式

public function index()
{
    return AppMemberModel::test();
}

you can also add the location to psr-4 in your composer.json

...
"autoload": {
    "classmap": [
        "database",
        "app/models"
    ],
    "psr-4": {
        "App": "app/",
    }
},

run composer dump-autoload you can inject the mode by name

use Model;
链接地址: http://www.djcxy.com/p/58136.html

上一篇: 在PHP中,命名空间是正斜杠?

下一篇: laravel 5 models类未找到