vendredi 29 mars 2019

Using pivot column data in a policy

I have an organization model ,broadcast model and a broadcast_organization pivot with an extra organization_specific column.I want to apply a policy for updating a broadcast only if organization_specific is true, so far none of the ways ive tried have worked.

Models

public function organizations()
{
    return $this->belongsToMany('App\Models\Organization')
    ->withPivot(['organization_specific']);
}


public function broadcasts()
{
    return $this->belongsToMany('App\Models\Broadcast')
    ->withPivot(['organization_specific']);
}

Broadcast Update Policy

 public function update(User $user, Broadcast $broadcast)
{

    if($this->isAdmin($user)){
        foreach($broadcast as $broadcasts) {
            if($broadcasts->pivot->organization_specific === 'true') {
                return true;
            }
        }
    }
    return false;
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire