VOOZH about

URL: https://deepwiki.com/hypervel/permission/1.2-installation-and-setup

⇱ Installation and Setup | hypervel/permission | DeepWiki


Loading...
Menu

Installation and Setup

This page provides step-by-step instructions for installing the hypervel/permission package, publishing configuration and migration files, and completing initial setup. For detailed configuration options, refer to page 5.2 (Configuration Reference). For database schema details, refer to page 4.1 (Database Migrations).

Package Installation

The hypervel/permission package is installed via Composer and requires PHP 8.2 or higher.

Composer Installation


The package automatically registers with supported frameworks through service provider auto-discovery mechanisms defined in composer.json39-51

Package Dependencies and Auto-Discovery


Sources: composer.json28-35 composer.json39-51

Framework Integration

The package supports both Hyperf and Hypervel frameworks through dedicated integration providers defined in composer.json39-51

Hyperf Framework Integration

Hyperf applications use Hypervel\Permission\ConfigProvider for dependency injection and command registration.

ConfigProvider Registration Flow


The ConfigProvider::__invoke() method returns an array with three sections:

Sources: src/ConfigProvider.php10-37 composer.json43-45

Hypervel Framework Integration

Hypervel applications use Hypervel\Permission\PermissionServiceProvider extending Hypervel\Support\ServiceProvider.

PermissionServiceProvider Lifecycle


The PermissionServiceProvider implements two methods:

Sources: src/PermissionServiceProvider.php9-39 composer.json46-49

Publishing Configuration and Migrations

After installation, publish the configuration file and database migrations to your application.

Publishing Commands

For Hyperf Applications:


For Hypervel Applications:


Published Files

Asset Publishing Mapping

























Asset TypePackage PathHyperf DestinationHypervel Destination
Configurationpublish/permission.phpconfig/autoload/permission.phpconfig/permission.php
Migrationdatabase/migrations/2025_07_02_000000_create_permission_tables.phpdatabase/migrations/2025_07_02_000000_create_permission_tables.phpdatabase/migrations/2025_07_02_000000_create_permission_tables.php

Sources: src/ConfigProvider.php21-34 src/PermissionServiceProvider.php27-38

Configuration Overview

The published permission.php configuration file controls permission system behavior. For detailed documentation of all options, refer to page 5.2 (Configuration Reference).

Configuration Structure

Configuration File Sections


Key Configuration Options

Configuration KeyLine RangePurposeDefault Value
models.rolepublish/permission.php29Role model class\Hypervel\Permission\Models\Role::class
models.permissionpublish/permission.php40Permission model class\Hypervel\Permission\Models\Permission::class
storage.database.connectionpublish/permission.php56Database connectionenv('DB_CONNECTION', 'mysql')
table_names.rolespublish/permission.php78Roles table name'roles'
table_names.permissionspublish/permission.php86Permissions table name'permissions'
table_names.role_has_permissionspublish/permission.php94Role-permission pivot'role_has_permissions'
table_names.owner_has_permissionspublish/permission.php102Owner-permission pivot'owner_has_permissions'
table_names.owner_has_rolespublish/permission.php110Owner-role pivot'owner_has_roles'
cache.expiration_secondspublish/permission.php168Cache TTL86400 (24 hours)
cache.storepublish/permission.php194Cache driverenv('PERMISSION_CACHE_STORE', 'default')
cache.keys.rolespublish/permission.php175Global roles cache key'hypervel.permission.cache.roles'

Sources: publish/permission.php1-196

Database Setup

After publishing the migration, execute it to create the required database tables.

Running Migrations

For Hyperf Applications:


For Hypervel Applications:


Migration Class Structure

The migration file defines an anonymous class extending Hypervel\Database\Migrations\Migration (database/migrations/2025_07_02_000000_create_permission_tables.php11):

Migration Methods


Created Tables

The migration creates five tables defined in database/migrations/2025_07_02_000000_create_permission_tables.php24-88:

Table NamePrimary KeyNotable ColumnsDefined At
rolesid (bigIncrements)name (unique), guard_namelines 28-35
permissionsid (bigIncrements)name (unique), guard_namelines 37-43
role_has_permissions[permission_id, role_id] (composite)is_forbidden (boolean)lines 44-53
owner_has_permissions[permission_id, owner_id, owner_type] (composite)is_forbidden (boolean), owner morphslines 55-64
owner_has_roles[role_id, owner_id, owner_type] (composite)owner morphslines 66-74

Entity Relationship Schema


Sources: database/migrations/2025_07_02_000000_create_permission_tables.php11-89

Verification

After completing the installation and setup, verify the system is working correctly:

  1. Check Configuration: Ensure config/permission.php exists and contains expected values
  2. Verify Database: Confirm the five permission tables exist in your database
  3. Test Integration: The package should now be available for use in your application models

The permission system is now ready for use. Next, you can add the HasPermission and HasRole traits to your application models. For detailed usage information, see HasPermission Trait and HasRole Trait.