所以我有“用户”模型和“用户设置”模型。“usersettings”模型有一个名为“users_id”的列,用于将其链接回用户模型。
我正在使用 spatie 权限和角色模块...
所以在用户模型中我有
use Spatie\Permission\Traits\HasRoles;
class User extends Model implements AuthenticatableContract, CanResetPasswordContract
{
use HasRoles;
......
public function usersettings()
{
#return $this->hasOne('\App\usersettings','users_id');
return $this->belongsTo('\App\usersettings','users_id');
}
}
在我的用户设置模型中
namespace App;
use Illuminate\Database\Eloquent\Model;
use Spatie\Permission\Traits\HasRoles;
class usersettings extends Model
{
use HasRoles;
protected $guard_name = 'web'; // or whatever guard you want to use
protected $table = 'usersettings';
protected $fillable = [
'users_id','stripe_customer',
];
//
}
在我的控制器中,我有
public function chooseUser(Request $request){
$theuserID = $request->input('id');
\Log::info('The User ID:'.$theuserID);
$whichuser = \App\User::find($theuserID)->with('usersettings')->get();
$whichuser2 = \App\User::find($theuserID);
/*if($isadmin = $whichuser2->hasRole('admin')){
$whichuser->admin ='isadmin';
}*/
#\Log::info('THE HAVE:'.$isadmin);
\Log::info('THE USER:'.$whichuser);
#$roles = $whichuser->getRoleNames();
#\Log::info('THE USER:'.$roles);
return $whichuser;
}
我的目标是返回所有用户信息以及用户设置以及查找用户是否具有管理员角色。我一直无法弄清楚如何将这三个放在一起。
我在想它可能是一个连接而不是一个实际,但是我不再有一个 uUser 模型并且不能使用spatie包中的方法。
谢谢R