Skip to content

Commit

Permalink
modify: 1. add permission tree 2. can be used as menu
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonlius committed Sep 12, 2018
1 parent 825786f commit d637b9b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions migrations/2015_01_26_115212_create_permissions_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public function up()
$table->string('slug')->unique();
$table->string('description')->nullable();
$table->string('model')->nullable();
$table->enum('is_show', [1, 0])->default(0)->comment('determine this permission is show when it is used as menu');
$table->integer('parent_id')->default(0)->change();
$table->timestamps();
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Permission extends Model implements PermissionHasRelationsContract
*
* @var array
*/
protected $fillable = ['name', 'slug', 'description', 'model'];
protected $fillable = ['name', 'slug', 'description', 'model', 'parent_id', 'is_show'];

/**
* Create a new model instance.
Expand Down
2 changes: 2 additions & 0 deletions src/Traits/HasRoleAndPermission.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ public function hasAllPermissions($permission)
public function checkPermission($permission)
{
return $this->getPermissions()->contains(function ($value) use ($permission) {
// it always true when 0 compare string (Str::is function)
$permission = is_numeric($permission) ? (string)$permission : $permission;
return $permission == $value->id || Str::is($permission, $value->slug);
});
}
Expand Down

0 comments on commit d637b9b

Please sign in to comment.