我需要在$hidden
事件内修改雄辩模型的retrieved
属性,该事件是静态函数,而$hidden
属性不是静态属性。任何帮助,我想做的就是在运行时隐藏一些属性?
public function makeHidden($attributes)
{
$this->hidden = array_merge($this->hidden, (array) $attributes);
return $this;
}
protected static function boot() {
parent::boot();
$user = JWTAuth::authenticate(JWTAuth::getToken());
if ($user === false) {
$user = Channel::authInfo();
$user->type = 'channel';
}
static::retrieved(function($model) use ($user) {
$this->makeHidden($this->toBeHidden[$user->type]);
});
}