Download the PHP package pierresilva/laravel-modules without Composer
On this page you can find all versions of the php package pierresilva/laravel-modules. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download pierresilva/laravel-modules
More information about pierresilva/laravel-modules
Files in pierresilva/laravel-modules
Informations about the package laravel-modules
Laravel Modules
Modules is a simple package to allow the means to separate your Laravel 5.3 application out into modules. Each module is completely self-contained allowing the ability to simply drop a module in for use.
Quick Installation
Begin by installing the package through Composer.
Once this operation is complete, simply add both the service provider and facade classes to your project's config/app.php
file:
Service Provider
Facade
Module Structure
The package is built with Laravel 5 in mind. Modules follow the same app structure adopted with the latest version of Laravel, ensuring that modules feel like a natural part of your application.
Manifest File
Along with the structure, every module has a module.json manifest file. This manifest file is used to outline information such as the description, version, author(s), and anything else you'd like to store pertaining to the module at hand.
- name - A human-friendly name of the module. Not required.
- slug - The slug of the module. This is used for identification purposes.
- version - The module's version. Not required.
- description - A description of the module. Not required.
- author - The module's author name. Not required
- license - The module's license. Not required
- order - The order of which modules are loaded. This is optional, but if you have a requirement to load a module later this is the option you are looking for. Not required
Configuration
Publishing The Config File
To publish the bundled config file, simply run Laravel's vendor:publish Artisan command:
Path to Modules
You may define the path where you'd like to store your modules.
Module's Base Namespace
Define the base namespace for your modules.
Note: Be sure to update this path if you move your modules to another directory.
To move modules folder
- Change configuration above.
- Add auto load namespace match folder in composer.json file. For example: "Modules\": "modules/". This will be move modules folder to Laravel base path.
- Run command composer dump-autoload in where composer.json installed.
Restructure your modules
You can alter the internal structure of your modules without affecting the scaffolding and migration commands. For example, if you want to put your php code in a src
directory and leave out the resources files you could do something like this:
Notice that the keys here are just based on the default module structure
Resources
Views
Module views are referenced using a double-colon module::view
syntax. So you may load the admin
view from the blog
module like so:
Overriding Module Views
Modules registers two locations for your views for each module: one in the application's resources/views/vendor
directory and one in your module's resources directory. So, using our blog example: when requesting a module view, Laravel will first check if a custom version of the view has been provided in resources/views/vendor/blog
. Then, if the view has not been customized, Laravel will search the module's view directory. This makes it easy for end-users to customize/override your module's views.
Translations
Modules registers the Resources/Lang
location for your translation files within each of your modules. Module translations are referenced using a double-colon module::file.line
syntax. So, you may load the blog
module's welcome
line from the messages file like so:
Public Assets
Just like packages for Laravel, your modules may have assets such as JavaScript, CSS, and images. To publish these assets to the application's public
directory, use the service provider's publishes
method. You may do this within your module's primary service provider, or create a service provider specifically for assets.
In this example, we'll be storing our assets in an Assets
directory at the root of our module. We will also add a modules
asset group tag, which may be used to publish groups of related assets:
Now, when you execute the vendor:publish
command, your module's assets will be copied to the specified location. Since you typically will need to overwrite the assets every time the module is updated, you may use the --force
flag:
If you would like to make sure your public assets are always up-to-date, you can add this command to the post-update-cmd
list in your composer.json
file.
Middleware
Modules comes bundled with middleware that you may use within your application. Below you will find a description of each one with examples of their uses.
The Identify Module middleware provides the means to pull and store module manifest information within the session on each page load. This provides the means to identify routes from specific modules.
Register
Simply register as a route middleware with a short-hand key in your app/Http/Kernel.php
file.
Usage
Now, you may simply use the middleware
key in the route options array. The IdentifyModule middleware expects the slug of the module to be passed along in order to locate and load the relevant manifest information.
Result
If you dd()
your session, you'll see that you have a new module
array key with your module's manifest information available.
Composer Support
Installation
To get started, simply require the plugin through Composer for your application:
Usage
Now, for every module that requires their own composer dependencies to be installed with your application, simply create a composer.json
file at the root of your module:
Then simply run composer update
per normal! Wikimedia's composer merge plugin will automatically parse all of your modules composer.json
files and merge them with your main composer.json
file dynamically.
Facade Reference
Module::all()
Get all modules.
Module::all()
Get all module slugs.
Module::where($key, $value)
Get modules based on where clause.
- $key (string) Module property key. Required.
- $value (mixed) Value to match. Required.
Module::sortBy($key)
Get modules based on where clause.
- $key (string) Module property key. Required.
Module::sortByDesc($key)
Sort modules by the given key in descending order.
- $key (string) Module property key. Required.
Module::exists($slug)
Check if given module exists.
- $slug (string) Module slug. Required.
Module::count()
Returns a count of all modules.
Module::getProperties($slug)
Returns the modules defined properties.
- $slug (string) Module slug. Required.
Module::get($property, $default)
Returns the given module manifest property.
- $property (string) Module property slug in the following format: moduleSlug::propertyKey. Required.
- $default (mixed) The default value if the defined property does not exist.
Module::set($property, $value)
Set the given module manifest property value.
- $propertySlug (string) Module property slug in the following format: moduleSlug::propertyKey. Required.
- $value (mixed) The new property value to be saved. Required
Module::enable($slug)
Enable the specified module.
- $slug (string) Module slug. Required.
Module::disable($slug)
Disable the specified module.
- $slug (string) Module slug. Required.
Module::enabled()
Gets all enabled modules.
Module::disabled()
Gets all disabled modules.
Module::isEnabled($slug)
Checks if specified module is enabled.
- $slug (string) Module slug. Required.
Module::isDisabled($slug)
Checks if specified module is disabled.
- $slug (string) Module slug. Required.
Artisan Commands
Modules package comes with a handful of Artisan commands to make generating and managing modules easy.
module:make [slug]
Generate a new module. This will generate all the necessary folders and files needed to bootstrap your new module. The new module will be automatically enabled and work out of the box.
module:make:controller [slug] [ControllerName]
Generate a new module controller class.
module:make:migration [slug] [migration_name]
Generate a new module migration file.
module:make:seeder [slug] [SeederName]
Generate a new module seeder file.
For migrate entry blog seders create a [ModuleName]DatabaseSeeder
class into Database\Seeders
folder module, and include your generate Sedder classes in run()
method.
module:make:request [slug] [RequestName]
Create a new module form request class.
module:make:test [slug] [TestName] [--unit]
Create a new module feature test class.
Create a new module unit test class.
After that the php artisan test
command can find the module tests classes.
module:enable [slug]
Enable a module.
module:list
List all application modules.
module:migrate [slug]
Migrate the migrations from the specified module or from all modules.
Migrate all modules.
Migrate specific module.
module:migrate:refresh [slug]
Reset and re-run all migrations for a specific or all modules.
Parameters
- --database - The database connection to use.
- --seed - Indicates if the seed task should be re-run.
module:migrate:reset [slug]
Rollback all database migrations for a specific or all modules.
Parameters
- --database - The database connection to use.
- --force - Force the operation to run while in production.
- --pretend - Dump the SQL queries that would be run.
Reset all modules migrations.
Reset specific module migrations.
module:migrate:rollback [slug]
Rollback the last database migrations for a specific or all modules.
Parameters
- --database - The database connection to use.
- --force - Force the operation to run while in production.
- --pretend - Dump the SQL queries that would be run.
Rollback all modules migrations.
Rollback specific module migrations.
module:seed [slug]
Seed the database with records for a specific or all modules.
Parameters
- --class - The class name of the module's root seeder.
- --database - The database connection to seed.
Seed all modules.
Seed specific module.