Download the PHP package dominikstyp/laravel-model-abstractor without Composer
On this page you can find all versions of the php package dominikstyp/laravel-model-abstractor. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dominikstyp/laravel-model-abstractor
More information about dominikstyp/laravel-model-abstractor
Files in dominikstyp/laravel-model-abstractor
Package laravel-model-abstractor
Short Description Makes AbstractModel inside app/models directory, changes make:model command to generate models which inherit from AbstractModel, and provides php artisan command to move your existing models to app/models directory and change their inheritance to AbstractModel. Thanks to that all your models will inherit from your custom class.
License MIT
Informations about the package laravel-model-abstractor
Laravel Model Abstractor
Makes AbstractModel inside app/models directory, changes make:model command,to generate models which inherit from AbstractModel,
and provides php artisan command to move your existing models to app/models directory and change their inheritance to AbstractModel.
Thanks to that all your models will inherit from your custom class.
Installation
Laravel >= 5.5
Due to package discovery feature introduced in Laravel 5.5, you don't have to add service provider to your providers any more.
Laravel < 5.5
For Laravel less than 5.5, you must add service provider to your config/app.php file, as follows:
Usage
Laravel Model Abstractor provides new console tasks:
Lists all your models which inherit from Eloquent\Model
Changes default models inheritance to AbstractModel,
and namespaces to App\Models, and moves them to app\Models directory.
WARNING! This doesn't affect User model, because it inherits from Authenticatable, so you must change it manually,
along with config/auth.php - providers section.
Example
Let's say you have a model file app/Dummy1.php which contains following code:
That model is generated automatically by command.
But you wish that your model (and others too) would inherit from your AbstractModel class like this:
With your AbstractModel looking like this:
All you have to do is invoke and you're done.
Additional Features
If you'll look into Models/Traits directory you'll find LocalScopes.php trait, which is attached to AbstractModel. LocalScopes provides you following functionality for all your models which inherit from AbstractModel (look at example below):