jeudi 1 septembre 2016

Laravel Global Scope with Dynamic Parameter

We're having issues using a global scope with a dynamic query parameter. The global scope is based on the manager ID, but $model is empty, and $this refers to the manager scope not the model so $this->id is an undefined property. Is there a way to do something like this:

public function apply(Builder $builder, Model $model)
{
    return $builder->where('manager', $model->id); // $this->id
}

I'm assuming that $model is supposed to be the manager model, but since it is empty and I can't find any documentation on it I'm not entirely sure. This is our global scope method in the Manager model:

protected static function boot()
{
    parent::boot();

    static::addGlobalScope(new ManagerScope);
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire