在检索到的事件中访问$ hidden属性

时间:2019-02-12 10:14:08

标签: laravel-5 eloquent

我需要在$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]);
        });
    }

0 个答案:

没有答案