JosephSilber / bouncer

Laravel Eloquent roles and abilities.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[HELP] Extend Ability

abkrim opened this issue · comments

I'm pretty desperate with the logic of extending the Ability model

I already created a migration so that the abilities table has an unsignedTinyInteger field called access_level that could effect the value 10.

I have tried both methods, extensions like use Silber\Bouncer\Database\Ability as BouncerAbility; or using the trait. useAbility;

However I am unable to use them and add my logic.
My case is that when I add an ability I need a method that allows me to capture before saving the model and its relationship, from the name of the ability, a string, and with it and my code I can obtain the access_level

That in its default adds the method that allows me when I use $user->allow($ability,$model)->someMetodh($levelInteger) or something similar.

I've been beating myself up for two hours. and I don't know how to do it.

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Silber\Bouncer\Database\Ability as BouncerAbility;

class Ability extends Model
{
    protected $guarded = ['id', 'created_at', 'updated_at'];

    // Code ??
    
    // How to call a method on save or attach the ability? 
}

After some problems, I get other way. Use Observer for update field.