Appearance
Application Level Utilities
Module Manager provides utilities that work not only with modules but also with the main Laravel application. This page explains how to use these features at the application level.
Policy Generation
You can generate policies for models in your main Laravel application, not just for modules. These policies follow Laravel's standard authorization pattern and integrate with Spatie's Permission system.
Command Line
bash
# Generate policies for all application models
php artisan mm:generate-policies --app
# Generate policies for specific application models
php artisan mm:generate-policies --app --model=User --model=Product
Programmatic Usage
php
use ModuleManager\ModuleManager\Internals\Services\PolicyGeneratorService;
// Generate policies for all application models
app(PolicyGeneratorService::class)->generateAppPolicies('all');
// Generate policies for specific models
app(PolicyGeneratorService::class)->generateAppPolicies(['User', 'Product']);
// Generate a policy for a specific model class
app(PolicyGeneratorService::class)->generatePolicyForModelClass('App\\Models\\User');
Working with Model Classes Directly
Module Manager now includes a helper method that can determine whether a model belongs to a module or to the main application, and generate policies accordingly:
php
// This will automatically detect if it's an application model
// or a module model and generate the appropriate policy
app(PolicyGeneratorService::class)->generatePolicyForModelClass($modelClass);
When to Use Application Level Policies
Use application level policies when:
- You have models in your main Laravel application that need policies
- You want a consistent permission approach across both modules and application
- You're building a modular application but keeping some core functionality in the main app