vdauchy / laravel-model-injector
Installs: 65
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/vdauchy/laravel-model-injector
Requires
- php: ^7.4|^8.0
- illuminate/database: *
- illuminate/support: *
This package is auto-updated.
Last update: 2025-10-21 08:51:35 UTC
README
Laravel Model Injector
This package is a simple trait to help on Model Injection.
The main goal is to replace class set in config as in laravel-permission:
// In: config/permission.php return [ 'models' => [ 'permission' => Permission::class, 'role' => Role::class, ], ... ]; // In: src/PermissionRegistrar.php public function __construct(CacheManager $cacheManager) { $this->permissionClass = config('permission.models.permission'); $this->roleClass = config('permission.models.role'); ... }
And instead do:
// In: src/PermissionRegistrar.php use HasModelInjection; public function __construct(CacheManager $cacheManager) { $this->permissionClass = $this->mClass(Permission::class); $this->roleClass = $this->mClass(Role::class); ... }
To use their own class, any developer can do:
$this->app->bind(Permission::class, MyCustomPermission::class);
Current API:
mQuery(string $model): Builder: Let you build a query against this Model.
mNew(string $model, array $attributes = []): Model: Let you create a new instance of this Model.
mClass(string $model): string: Return the class associated to the Model.
mTable(string $model): string: Return the table's name of the Model".
mColumns(string $model): Collection: Return a Collection of columns.