Php 与扩展用户模型sentinel-laravel包的雄辩关系

Php 与扩展用户模型sentinel-laravel包的雄辩关系,php,laravel-5,eloquent,cartalyst-sentinel,Php,Laravel 5,Eloquent,Cartalyst Sentinel,我有一个类用户可以扩展 <?php namespace App; class User extends \Cartalyst\Sentinel\Users\EloquentUser { public function chalets(){ return $this->hasMany('App\Chalet'); } } 我有按用户添加小屋的方法: public function postCreateChalet(Request $request)

我有一个类用户可以扩展

<?php

namespace App;

class User extends \Cartalyst\Sentinel\Users\EloquentUser
{
    public function chalets(){
        return $this->hasMany('App\Chalet');
    }
}
我有按用户添加小屋的方法:

public function postCreateChalet(Request $request){
        $chalet = new Chalet([
            'name' => $request->input('name'),
            'description' => $request->input('description')
        ]);
        Sentinel::getUserRepository()->setModel('App\User');
        $user = Sentinel::getUser();
        $user->chalets()->save($chalet);
        return ('chalet has created');
    }
这给了我一个错误:

BadMethodCallException
Call to undefined method Cartalyst\Sentinel\Users\EloquentUser::chalets()
这是扩展用户类的正确方法吗

我已经找到了扩展用户类的方法。我发现了这样一个问题:虽然没有帮助我


我使用的是Laravel 5.7

您得到的异常表明Sentinel仍然是指默认的stock Sentinel的EloquentUser模型。确保指向具有已发布Sentinel配置的扩展用户模型

  • 运行下面的命令

    php artisan vendor:publish --provider="Cartalyst\Sentinel\Laravel\SentinelServiceProvider"
    
  • 在“config\cartalyst.sentinel.php”打开已发布的配置文件

  • 从以下内容对其进行修改:
    
    “用户”=>[
    'model'=>'Cartalyst\Sentinel\Users\EloquentUser',
    ],
    
    致:
    
    “用户”=>[
    'model'=>'App\User',
    ],
    

  • 有关更多信息,请参阅

    通过config配置后,不需要以下行:

    Sentinel::getUserRepository()->setModel('App\User');
    
    Sentinel::getUserRepository()->setModel('App\User');