PHPackages                             ghazym/laravel-module-suite - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. ghazym/laravel-module-suite

ActiveLibrary[Framework](/categories/framework)

ghazym/laravel-module-suite
===========================

A comprehensive Laravel package for building modular applications with RBAC, media management, and API endpoints

2.0.11(2mo ago)3941MITPHPPHP ^8.1|^8.2|^8.3

Since May 18Pushed 2w ago1 watchersCompare

[ Source](https://github.com/MagdyGhazy/laravel-module-suite)[ Packagist](https://packagist.org/packages/ghazym/laravel-module-suite)[ RSS](/packages/ghazym-laravel-module-suite/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (6)Versions (23)Used By (0)

Laravel Module Suite
====================

[](#laravel-module-suite)

A comprehensive Laravel package for building modular applications with RBAC, media management, and API endpoints.

Prerequisites
-------------

[](#prerequisites)

Before using this package, ensure you have:

1. Laravel 9.x, 10.x, 11.x, or 12.x installed
2. For Laravel 11.x or higher, you need to install the API package:

```
php artisan install:api
```

Features
--------

[](#features)

- Role-Based Access Control (RBAC) with polymorphic relationships
- Media management with file uploads and storage
- Custom module generation
- Permission management
- API endpoints for roles and permissions
- Repository pattern implementation
- Standardized API responses

Requirements
------------

[](#requirements)

- PHP &gt;= 8.1
- Laravel &gt;= 10.0
- Composer

Installation
------------

[](#installation)

```
composer require ghazym/laravel-module-suite
```

Publish the configuration and migrations:

```
php artisan vendor:publish --provider="Ghazym\LaravelModuleSuite\LaravelModuleSuiteServiceProvider"
```

Run the migrations:

```
php artisan migrate
```

Seed the default permissions and roles:

```
php artisan db:seed --class=PermissionSeeder
php artisan db:seed --class=RoleSeeder
```

Module Generation
-----------------

[](#module-generation)

Generate a new module with all necessary files:

```
php artisan make:module ModuleName
```

This command will create:

- Controller with API endpoints
- Model with relationships
- Service class for business logic
- Form Request classes for validation
- API Resource for handling list and detail views
- Migration file
- Seeder file
- Repository trait for data access
- Response trait for standardized API responses

Usage
-----

[](#usage)

### Roles and Permissions

[](#roles-and-permissions)

The package provides a polymorphic role system that can be used with any model:

```
use Ghazym\LaravelModuleSuite\Traits\HasPermissions;

class User extends Model
{
    use HasPermissions;
}

class Team extends Model
{
    use HasPermissions;
}
```

#### Assigning Roles

[](#assigning-roles)

```
// Assign a role to a model
$user->assignRole(1);                    // Using role ID
$user->assignRole('admin');              // Using role name
$user->assignRole($roleModel);           // Using role model instance

// Assign multiple roles
$user->syncRoles([1, 2, 3]);            // Replace all roles

// Remove a role to a model
$user->removeRole(1);                    // Using role ID
$user->removeRole('admin');              // Using role name
$user->removeRole($roleModel);           // Using role model instance
```

#### Checking Permissions

[](#checking-permissions)

```
// Get all permissions for a model
$permissions = $user->getPermissions();  // Returns array of permission names

// Check permissions
$user->hasPermission('edit user');       // Check single permission
$user->hasAnyPermission(['create user', 'edit user']);  // Check if model has any of these permissions
$user->hasAllPermissions(['create user', 'edit user']); // Check if model has all of these permissions
```

### Media Management

[](#media-management)

The package includes a media management system with automatic file cleanup:

```
use Ghazym\LaravelModuleSuite\Traits\HasMedia;

class Post extends Model
{
    use HasMedia;
}
```

#### Managing Media

[](#managing-media)

```
// Add media
$model->addMedia($file, $mediaName, $folderName);

// Add multiple files
$model->addMultipleMedia($files, $mediaName, $folderName);

// Get media
$model->getMedia('profile_image');           // Get all media with name
$model->getFirstMedia('id_images');          // Get first media
$model->getLastMedia('licence_images');      // Get last media

// Update media
$model->updateMedia($media, $newFile, $name, $folder);
$model->updateMultipleMedia($files, $name, $folder, $keepMediaIds);

// Remove media
$model->removeMedia($media);                 // Remove single media
$model->removeMultipleMedia($name);          // Remove all media with name
$model->removeAllMedia();                    // Remove all media (automatic on model delete)
```

### Configuration

[](#configuration)

The package is highly configurable through the `config/laravel-module-suite.php` file:

```
// Example configuration
return [
    'media' => [
        'max_size' => 10 * 1024 * 1024, // 10MB
        'allowed_mimes' => ['image/jpeg', 'image/png', 'image/gif'],
        'disk' => [
            'default' => 'public',
            'types' => [
                'image' => 'public',
                'document' => 'local',
            ],
        ],
    ],
    // ... other configurations
];
```

Repository Query Parameters
---------------------------

[](#repository-query-parameters)

You can customize queries when using the repository helpers by passing an array of parameters. The trait already supports `select`, `relations`, various `where*` clauses, searching, ordering, etc. Here are a few examples showing the new options you've added:

```
$parameters = [
    'select'    => ['id', 'name', 'description'],

    'relations' => ['owner:id,name'],

    'where' => [
                ['status', '=', 'active'],
                ['last_seen', '
