lexxyungcarter / laravel-modules
Laravel Module management
Requires
- php: >=7.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.7
- laravel/framework: 5.6.*
- mockery/mockery: ~1.0
- orchestra/testbench: ^3.6
- phpstan/phpstan: ^0.9.2
- phpunit/phpunit: ~7.0
- spatie/phpunit-snapshot-assertions: ^1.0
- dev-master / 4.0.x-dev
- 3.3.1
- 3.3.0
- 3.2.1
- 3.2.0
- 3.1.0
- 3.0.1
- 3.0.0
- 2.7.0
- 2.6.0
- 2.5.0
- 2.4.1
- 2.4.0
- 2.3.0
- 2.2.1
- 2.2.0
- 2.1.0
- 2.0.x-dev
- 2.0.0
- 1.27.2
- 1.27.1
- 1.27.0
- 1.26.0
- 1.25.1
- 1.25.0
- 1.24.0
- 1.23.0
- 1.22.0
- 1.21.0
- 1.20.0
- 1.19.0
- 1.18.0
- 1.17.1
- 1.17.0
- 1.16.0
- 1.15.0
- 1.14.0
- 1.13.1
- 1.13.0
- 1.0.x-dev
- 0.12.0
- 0.11.2
- 0.11.1
- 0.11.0
- 0.10
- 0.9
- 0.8
- 0.7
- 0.6
- 0.5
- 0.4
- 0.3
- 0.2
- 0.1
This package is auto-updated.
Last update: 2024-11-21 21:31:39 UTC
README
Why This Fork?
- Prefix module name when creating table for the module
- Added
--api
option when generating controller
The main branch is an excellent work of art! But sometimes when you are building a Module, you need the migration table to have the module's name prefix so as to avoid collision with other tables, and/or keep modules clean. It's arguably easier to view all tables used by the module at a glance, and also avoid collisions with other modules which would potentially use the same table (e.g. Role, Department, Category models) This package will generate a migration table prefixed with the module's name.
# artisan command. Syntax: model name, module name, -m (migration flag) -p (prefix flag) php artisan module:make-model Person Hr -pm # API Controllers generation php artisan module:make-controller Postcontroller --api
Output
Model:
<?php namespace $NAMESPACE$; // namespace will be autofilled use Illuminate\Database\Eloquent\Model; class Person extends Model { /** * The attributes that are mass assignable. * * @var array */ protected $fillable = $FILLABLE$; // fillable properties will be inserted here if specified /** * The table associated with the model. * * @var string */ protected $table = "hr_persons"; // auto-generates this in model // }
Migration
// 2018_03_25_210616_create_hr_persons_table.php <?php use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateHrPersonsTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('hr_persons', function (Blueprint $table) { $table->increments('id'); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('hr_persons'); } }
The automatic appending of module-name in table name is done Only when making a model with the migration switch. It Does Not affect the php artisan module:make-migration just in case you need to generate other migrations to do other stuffs without appending the module name.
Install
To install through Composer, by run the following command:
composer require lexxyungcarter/laravel-modules
The package will automatically register a service provider and alias.
Optionally, publish the package's configuration file by running:
php artisan vendor:publish --provider="Nwidart\Modules\LaravelModulesServiceProvider"
NB: Namespacing has been preserved to the parent's repo for easier migration between the packages. However, if coming from the parent repo, you should uninstall the package before requiring this package to avoid collisions.
Updates
This package will always be kept in sync with the parent repo. No need to worry about obsoleteness.
Future
- Add laracasts/Laravel-5-Generators-Extended features into the package to extend migration command features. (Maybe you'll fork it and push it here? That would be GREAT!)
Credits
Readme From Forked Project
nwidart/laravel-modules
is a Laravel package which created to manage your large Laravel app using modules. Module is like a Laravel package, it has some views, controllers or models. This package is supported and tested in Laravel 5.
This package is a re-published, re-organised and maintained version of pingpong/modules, which isn't maintained anymore. This package is used in AsgardCMS.
With one big added bonus that the original package didn't have: tests.
Find out why you should use this package in the article: Writing modular applications with laravel-modules.
The package will automatically register a service provider and alias.
Optionally, publish the package's configuration file by running:
php artisan vendor:publish --provider="Nwidart\Modules\LaravelModulesServiceProvider"
Autoloading
By default the module classes are not loaded automatically. You can autoload your modules using psr-4
. For example:
{ "autoload": { "psr-4": { "App\\": "app/", "Modules\\": "Modules/" } } }
Tip: don't forget to run composer dump-autoload
afterwards.
Documentation
You'll find installation instructions and full documentation on https://nwidart.com/laravel-modules/.
Credits
About Nicolas Widart
Nicolas Widart is a freelance web developer specialising on the Laravel framework. View all my packages on my website, or visit my website.
License
The MIT License (MIT). Please see License File for more information.