triun / laravel-model-base
Generate Eloquent Model Bases for Laravel
Installs: 6 421
Dependents: 1
Suggesters: 1
Security: 0
Stars: 2
Watchers: 2
Forks: 0
Open Issues: 5
Requires
- php: ^8.0.2
- doctrine/dbal: ^3.3
- illuminate/config: ^9.0
- illuminate/console: ^9.0
- illuminate/database: ^9.0
- illuminate/filesystem: ^9.0
- illuminate/support: ^9.0
- triun/diff: ^1.0
Requires (Dev)
- laravel/framework: ^9.0
- laravel/lumen-framework: ^9.0
- nunomaduro/collision: ^6.2
- nunomaduro/larastan: ^2.1
- orchestra/testbench: ^7.0
- phpcompatibility/php-compatibility: *
- phpstan/phpstan: ^1.6
- phpunit/phpunit: ^9.5.10
- squizlabs/php_codesniffer: ^3.4
Suggests
- triun/laravel-model-validable: Model validation and rules generator modifier
- 9.x-dev
- v9.1.0
- v9.0.3
- v9.0.2
- v9.0.1
- v9.0.0
- 6.x-dev
- 6.0.14
- 6.0.13
- 6.0.12
- 6.0.11
- 6.0.10
- 6.0.9
- 6.0.8
- 6.0.7
- 6.0.6
- 6.0.5
- 6.0.4
- 6.0.3
- 6.0.2
- 6.0.1
- 6.0.0
- 5.8.x-dev
- 5.8.4
- 5.8.3
- 5.8.2
- 5.8.1
- 5.8.0
- 5.7.x-dev
- 5.7.0
- 5.6.x-dev
- 5.6.2
- 5.6.1
- 5.6.0
- 5.5.x-dev
- 5.5.1
- 5.5.0
- 5.4.x-dev
- 5.4.1
- 5.2.x-dev
- v5.2.0
- dev-new-10x
- dev-dependabot/composer/guzzlehttp/psr7-2.5.0
This package is auto-updated.
Last update: 2024-11-13 03:58:16 UTC
README
Generate Eloquent Model Base for Laravel.
About
Laravel-Model-Base is a Laravel command to perform repetitive tasks while creating new models, and saving it into a abstract model base, so you can update it any time, without need to worry about overwriting your manual changes in the model.
The main goal of the model base it's generate eloquent configurations based on the database table architecture, meaning that it could not be any business logic implemented, or any other logic not comming from the database itself. If you are interested in adding extra properties, methods, interfaces or traits, you can do so in the model itself.
This generator can be customised by the config parameters, but it can also be extended by the modifiers.
The model will be optionally generated too, but in this case, it will never be able to be overwritten by this tool.
Installation
Require this package with composer using the following command:
composer require --dev triun/laravel-model-base
After updating composer, add the service provider to the providers array in config/app.php
Triun\ModelBase\ModelBaseServiceProvider::class,
Development only installation
To install this package on only development systems, add the --dev
flag to your composer command:
composer require --dev triun/laravel-model-base:dev-master
Instead of adding the service provider in the config/app.php
file, you should add the following code to your app/Providers/AppServiceProvider.php
file, within the register()
method:
public function register() { if ($this->app->environment() !== 'production') { $this->app->register(\Triun\ModelBase\ModelBaseServiceProvider::class); } // ... }
This will allow your application to load the Laravel Model Base on non-production environments.
Usage
To create one model base
php artisan make:mode-base table_name [--connection connection_name]
For Bulk creation
php artisan make:mode-base-bulk [--connection connection_name]
Note: If you don't set up the connections in the config file (model-base.bulk.connections
),
it will try to run all available connections from your database config file (database.connections
).
Customize
You can publish the configuration file into your app with:
php artisan vendor:publish --provider="Triun\ModelBase\ModelBaseServiceProvider" --tag=config
Lumen
If you are using Lumen, you may need to do some manual steps...
Copy the config file into your config
directory:
cp vendor/triun/laravel-model-base/config/model-base.php config/
And you may also need to uncomment the following lines in bootstrap/app.php
file:
<?php # bootstrap/app.php $app = new Laravel\Lumen\Application( realpath(__DIR__.'/../') ); $app->withFacades(true, [ Illuminate\Support\Facades\App::class => 'App', Illuminate\Support\Facades\File::class => 'File', ]); $app->withEloquent(); $app->register(App\Providers\AppServiceProvider::class);
So we can use Facades and Eloquent, as well as add some content in the AppServiceProvider
:
<?php namespace App\Providers; use Illuminate\Support\ServiceProvider; class AppServiceProvider extends ServiceProvider { public function register() { $this->app->instance('path.config', app()->basePath() . DIRECTORY_SEPARATOR . 'config'); if ($this->app->environment() !== 'production') { $this->app->configure('model-base'); $this->app->register(\Triun\ModelBase\ModelBaseServiceProvider::class); } } }
// TODO
Besides the configuration file, you can also add or create your own modifiers.
Modifiers
If you want to add behaviours to the generator, you can do so using the skeleton modifiers.
Modifiers Packages
Those are some modifiers packages:
// TODO
Add modifiers
If you already have any modifier package, you can load it by adding it in the config/model-base.php
file, in the 'modifiers' array.
// TODO
Create your own modifiers
How to create a modifier.
// TODO
Documentation
The documentation for Laravel-Model-Base is available on the Github wiki.
Issues
Bug reports and feature requests can be submitted on the Github Issue Tracker.
Contributing
See CONTRIBUTING.md for information.
License
The Laravel Model Base is open-sourced software licensed under the MIT license