Silber\Bouncer\Database\Models::isOwnedBy PHP Метод

isOwnedBy() публичный статический Метод

Determines whether the given model is owned by the given authority.
public static isOwnedBy ( Model $authority, Model $model ) : boolean
$authority Illuminate\Database\Eloquent\Model
$model Illuminate\Database\Eloquent\Model
Результат boolean
    public static function isOwnedBy(Model $authority, Model $model)
    {
        $type = strtolower(static::basename($model));
        if (isset(static::$ownership[$type])) {
            $attribute = static::$ownership[$type];
        } elseif (isset(static::$ownership['*'])) {
            $attribute = static::$ownership['*'];
        } else {
            $attribute = strtolower(static::basename($authority)) . '_id';
        }
        return static::isOwnedVia($attribute, $authority, $model);
    }

Usage Example

Пример #1
0
 /**
  * Determine if any of the abilities can be matched against the provided applicable ones.
  *
  * @param  \Illuminate\Support\Collection  $abilities
  * @param  \Illuminate\Support\Collection  $applicable
  * @param  \Illuminate\Database\Eloquent\Model  $model
  * @param  \Illuminate\Database\Eloquent\Model  $authority
  * @return int|null
  */
 protected function findMatchingAbility($abilities, $applicable, $model, $authority)
 {
     $abilities = $abilities->toBase()->pluck('identifier', 'id');
     if ($id = $this->getMatchedAbilityId($abilities, $applicable)) {
         return $id;
     }
     if ($model instanceof Model && Models::isOwnedBy($authority, $model)) {
         return $this->getMatchedAbilityId($abilities, $applicable->map(function ($identifier) {
             return $identifier . '-owned';
         }));
     }
 }