- PHP 5.4 or higher
If you find this source useful, you can share some milk to me if you want ^_^
1.0.10 to 1.0.11
- See #26
1.0.9 to 1.0.10
- Added support for #13 : enable and disable module.
- There is new artisan command
module:enable
andmodule:disable
.
1.0.8 to 1.0.9
- Fix
module:seed-make
command when runningmodule:make
command. - Command Improvement.
1.0.7 to 1.0.8
- There is command name changed :
php artisan module:migrate:make
tophp artisan module:migration
php artisan module:seed:make
tophp artisan module:seed-make
- Merged #8 : Fix constructor error.
- Package improvement.
Open your composer.json file and add a new required package.
"pingpong/modules": "1.0.*"
Next, open a terminal and run.
composer update
Next, Add new service provider in app/config/app.php
.
'Pingpong\Modules\ModulesServiceProvider',
Next, Add new class alias in app/config/php
.
'Module' => 'Pingpong\Modules\Facades\Module',
Next, publish package configuration. Open your terminal and run:
php artisan config:publish pingpong/modules
Done.
By default modules folder is in your Laravel route directory. For first use, please run this command on your terminal.
php artisan module:setup
Now, naming modules must use a capital letter on the first letter. For example: Blog, News, Shop, etc.
app/
public/
vendor/
Modules
|-- Blog
|-- commands/
|-- config/
|-- controllers/
|-- database/
|-- migrations/
|-- seeds/
|-- models/
|-- start/
|-- global.php
|-- tests/
|-- views/
|-- BlogServiceProvider.php
|-- filters.php
|-- routes.php
|-- module.json
Note: File start/global.php
is required for registering View
, Lang
and Config
namespaces. If that file does not exist, an exception FileMissingException
is thrown.
Create new module.
php artisan module:make blog
Create new command for the specified module.
php artisan module:command CustomCommand blog
php artisan module:command CustomCommand blog --command=custom:command
php artisan module:command CustomCommand blog --namespace=Modules\Blog\Commands
Create new migration for the specified module.
php artisan module:migration users blog
php artisan module:migration users blog --fields="username:string, password:string"
Create new seed for the specified module.
php artisan module:seed-make users blog
Migrate from the specified module.
php artisan module:migrate blog
Migrate from all modules.
php artisan module:migrate
Seed from the specified module.
php artisan module:seed blog
Seed from all modules.
php artisan module:seed
Create new controller for the specified module.
php artisan module:controller SiteController blog
Publish assets from the specified module to public directory.
php artisan module:publish blog
Publish assets from all modules to public directory.
php artisan module:publish
Create new model for the specified module.
php artisan module:model User blog
Publish migration for the specified module or for all modules.
This helpful when you want to rollback the migrations. You can also run php artisan migrate
instead of php artisan module:migrate
command for migrate the migrations.
For the specified module.
php artisan module:publish-migration blog
For all modules.
php artisan module:publish-migration
Enable the specified module.
php artisan module:enable blog
Disable the specified module.
php artisan module:disable blog
Get asset url from specified module.
Module::asset('blog', 'image/news.png');
Generate new stylesheet tag.
Module::style('blog', 'image/all.css');
Generate new stylesheet tag.
Module::script('blog', 'js/all.js');
Get all modules.
Module::all();
Get all enabled module.
Module::enabled();
Get all disabled module.
Module::disabled();
Get modules path.
Module::getPath();
Get assets modules path.
Module::getAssetsPath();
Get module path for the specified module.
Module::getModulePath('blog');
Enable a specified module.
Module::enable('blog')
Disable a specified module.
Module::disable('blog')
Get module json property as array from a specified module.
Module::getProperties('blog')
NEW!
Use the specified module.
php artisan module:use blog
When you create your create new module, it also creates a new custom service provider. For example, if you create a new module named blog
, it also creates a new Service Provider named BlogServiceProvider
with namespace Modules\Blog
. I think it is useful for registering custom command for each module. This file is not autoloaded; you can autoload this file using psr-0
or psr-4
. That file maybe look like this:
<?php namespace Modules\Blog;
use Illuminate\Support\ServiceProvider;
class BlogServiceProvider extends ServiceProvider {
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
//
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return array();
}
}
When you create a new module it also registers new custom namespace for Lang
, View
and Config
. For example, if you create a new module named blog
, it will also register new namespace/hint blog
for that module. Then, you can use that namespace for calling Lang
, View
or Config
.
Following are some examples of its usage:
Calling Lang:
Lang::get('blog::group.name')
Calling View:
View::make('blog::index')
View::make('blog::partials.sidebar')
Calling Config:
Config::get('blog::group.name')
This package is open-sourced software licensed under the MIT license