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"
“用户”=>[
'model'=>'Cartalyst\Sentinel\Users\EloquentUser',
],
致:
“用户”=>[
'model'=>'App\User',
],
Sentinel::getUserRepository()->setModel('App\User');
Sentinel::getUserRepository()->setModel('App\User');