- 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
<?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
//
}
// 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.
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.
This package will always be kept in sync with the parent repo. No need to worry about obsoleteness.
- 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!)
Laravel | laravel-modules |
---|---|
5.4 | ^1.0 |
5.5 | ^2.0 |
5.6 | ^3.0 |
5.7 | ^4.0 |
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"
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.
You'll find installation instructions and full documentation on https://nwidart.com/laravel-modules/.
Nicolas Widart is a freelance web developer specialising on the Laravel framework. View all my packages on my website, or visit my website.
The MIT License (MIT). Please see License File for more information.