table() public static method

Get a custom table name mapping for the given table.
public static table ( string $table ) : string
$table string
return string
 /**
  * Reverse the migrations.
  *
  * @return void
  */
 public function down()
 {
     Schema::drop(Models::table('permissions'));
     Schema::drop(Models::table('assigned_roles'));
     Schema::drop(Models::table('roles'));
     Schema::drop(Models::table('abilities'));
 }
 /**
  * Reverse the migrations.
  *
  * @return void
  */
 public function down()
 {
     Schema::drop(Models::table('role_abilities'));
     Schema::drop(Models::table('user_abilities'));
     Schema::drop(Models::table('user_roles'));
     Schema::drop(Models::table('roles'));
     Schema::drop(Models::table('abilities'));
 }
Ejemplo n.º 3
0
 /**
  * Get the callback to constrain an abilities query to the given ability.
  *
  * @param  string  $ability
  * @param  \Illuminate\Database\Eloquent\Model|string|null  $model
  * @return \Closure
  */
 protected function getAbilityConstraint($ability, $model)
 {
     return function ($query) use($ability, $model) {
         $table = Models::table('abilities');
         $query->where("{$table}.name", $ability);
         if (!is_null($model)) {
             $query->forModel($model);
         }
     };
 }
Ejemplo n.º 4
0
 /**
  * Get a constraint for abilities that have been granted to the given authority.
  *
  * @param  \Illuminate\Database\Eloquent\Model  $authority
  * @param  bool  $allowed
  * @return \Closure
  */
 protected function getAuthorityConstraint(Model $authority, $allowed)
 {
     return function ($query) use($authority, $allowed) {
         $permissions = Models::table('permissions');
         $abilities = Models::table('abilities');
         $table = $authority->getTable();
         $prefix = Models::prefix();
         $query->from($table)->join($permissions, $table . '.id', '=', $permissions . '.entity_id')->whereRaw("{$prefix}{$permissions}.ability_id = {$prefix}{$abilities}.id")->where("{$permissions}.entity_type", $authority->getMorphClass())->where("{$permissions}.forbidden", !$allowed)->where("{$table}.{$authority->getKeyName()}", $authority->getKey());
     };
 }
Ejemplo n.º 5
0
 /**
  * Constrain the given roles query to those that were assigned to the given authorities.
  *
  * @param  \Illuminate\Database\Eloquent\Builder  $query
  * @param  string|\Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection  $model
  * @param  array  $keys
  * @return void
  */
 public function constrainWhereAssignedTo($query, $model, array $keys = null)
 {
     list($model, $keys) = Helper::extractModelAndKeys($model, $keys);
     $query->whereExists(function ($query) use($model, $keys) {
         $table = $model->getTable();
         $key = "{$table}.{$model->getKeyName()}";
         $pivot = Models::table('assigned_roles');
         $roles = Models::table('roles');
         $prefix = Models::prefix();
         $query->from($table)->join($pivot, $key, '=', $pivot . '.entity_id')->whereRaw("{$prefix}{$pivot}.role_id = {$prefix}{$roles}.id")->where("{$pivot}.entity_type", $model->getMorphClass())->whereIn($key, $keys);
     });
 }
Ejemplo n.º 6
0
 /**
  * The roles relationship.
  *
  * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
  */
 public function roles()
 {
     return $this->belongsToMany(Models::classname(Role::class), Models::table('user_roles'), 'user_id');
 }
Ejemplo n.º 7
0
 /**
  * The Abilities relationship.
  *
  * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
  */
 public function abilities()
 {
     return $this->belongsToMany(Models::classname(Ability::class), Models::table('user_abilities'));
 }
Ejemplo n.º 8
0
 /**
  * Constructor.
  *
  * @param array  $attributes
  */
 public function __construct(array $attributes = [])
 {
     $this->table = Models::table('roles');
     parent::__construct($attributes);
 }
Ejemplo n.º 9
0
 /**
  * Constructor.
  *
  */
 public function __construct()
 {
     $this->table = Models::table('abilities');
 }
Ejemplo n.º 10
0
 /**
  * The roles relationship.
  *
  * @return \Illuminate\Database\Eloquent\Relations\MorphToMany
  */
 public function roles()
 {
     return $this->morphToMany(Models::classname(Role::class), 'entity', Models::table('assigned_roles'));
 }
Ejemplo n.º 11
0
 /**
  * The users relationship.
  *
  * @return \Illuminate\Database\Eloquent\Relations\MorphToMany
  */
 public function users()
 {
     return $this->morphedByMany(Models::classname(User::class), 'entity', Models::table('permissions'));
 }
Ejemplo n.º 12
0
 /**
  * The abilities relationship.
  *
  * @return \Illuminate\Database\Eloquent\Relations\MorphToMany
  */
 public function abilities()
 {
     return $this->morphToMany(Models::classname(Ability::class), 'entity', Models::table('permissions'));
 }
Ejemplo n.º 13
0
 /**
  * Retract the role from the given model(s).
  *
  * @param  string|\Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection  $model
  * @param  array|null  $keys
  * @return $this
  */
 public function retractFrom($model, array $keys = null)
 {
     list($model, $keys) = Helper::extractModelAndKeys($model, $keys);
     $this->newBaseQueryBuilder()->from(Models::table('assigned_roles'))->where('role_id', $this->getKey())->where('entity_type', $model->getMorphClass())->whereIn('entity_id', $keys)->delete();
     return $this;
 }
Ejemplo n.º 14
0
 /**
  * The users relationship.
  *
  * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
  */
 public function users()
 {
     return $this->belongsToMany(Models::classname(User::class), Models::table('user_roles'));
 }