Download the PHP package sebastiaanluca/laravel-module-loader without Composer

On this page you can find all versions of the php package sebastiaanluca/laravel-module-loader. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-module-loader

A lightweight package to split your code into contextual modules

Latest stable release Build status Total downloads

Read my blog View my other packages and projects Follow @sebastiaanluca on Twitter Share this package on Twitter

Laravel Module Loader helps you organize your project by splitting your domain code in contextual modules.

By default, Laravel provides you with an app/ directory to put all your classes in. In medium to large projects, you usually end up having a monolithic app/ directory with tens or hundreds of directories and classes. To make some sense of that, they're typically organized per type of class (e.g. providers, services, models, …) too.

An alternative to that is organizing your code in groups that belong in the same context, i.e. modules. Since you usually develop one feature at a time, it makes it easier for you and other developers to find related code when working in that context.

Additionally, this lightweight module package provides some added benefits when making use of the include module service provider, including:

Example

To give you a sense of how a modularized project is structured, take for instance a users, documents, and a shopping cart module:

Table of contents

Requirements

How to install

Via Composer:

Getting started

There's only one required step to get started and that is to create a module.

Creating a module

Say you want to create a module to group all your user related classes and files, run:

and the package will:

Of course you can also do all of this manually. Create a User and User/src directory in any of your module directories and run php artisan modules:refresh afterwards to add it to your composer.json file (or do so manually too).

Caching in production environments

Optional

To reduce the amount of files being read during application boot, you can opt to cache a list of your module service providers to improve load time. In addition to Composer providing a cached list of all your module classes, the package reads just the one cache file on boot and registers those instead of scanning all your module directories and loading them on-the-fly. Especially useful in production environments and advised to run during project deployment.

To cache all providers, run:

To clear the cache file, execute:

Going into detail

Scanning and registering modules

When you've manually created a new module, made some changes, added directories that need autoloading, and so on, you should refresh your modules:

This will scan all your module directories for changes, write your modules' autoload configuration to composer.json (both classmap, PSR-4, and PSR-4 dev sections when applicable), and automatically update the Composer autoloader.

Your existing Composer configuration is not altered and no autoload entries are altered, unless:

If you wish to keep all autoload entries for modules that do not exist, you can use the --keep option:

Using a module service provider

Optional

A module should contain a service provider if you want your module to support:

When you create a module, a service provider is generated for you. If you want to create a provider yourself and have it automatically be registered on framework boot, create a class extending the correct base provider in your module's src/Providers directory.

Pay extra attention to the studly cased naming of your provider, as it's only registered on boot if the class name starts with your module name.

Individual module configuration

Optional; requires a module service provider

Each module can contain a configuration file which you can use to group related settings. The snake-cased naming and location of the configuration file is important if you want it auto-loaded. Take for instance a ShoppingCart module:

The contents of the file are similar to any other Laravel configuration file and can contain anything you want:

To retrieve a setting, call it like so:

Publishing a module's configuration

Optional; requires a module service provider

If you don't want the configuration to reside in the module itself, you can either copy or move it to the root /config directory. Another option is to publish it like you would do for a package configuration file, i.e. let Laravel copy it for you:

Then choose * YourModule (configuration) from the list.

Note that both configuration files will be merged ,but the one in the root /config directory will take precedence over the one in your module. If a same key is encountered in both files, the one from within your module will be ignored.

Using migrations

Optional; requires a module service provider

Laravel Module Loader gives you 2 options when it comes to organizing migrations. Either you keep them in your default /database/migrations directory and maintain a chronological overview of all your migrations, or you store them contextually per module in e.g. YourModule/database/migrations.

Both locations are fine and interchangeable; i.e. you can combine both uses as they are sorted and executed by their date and time prefix.

Using factories

Optional; requires a module service provider

Factories can be stored in your default /database/factories directory or per module in e.g. YourModule/database/factories. They are by default not namespaced and only loaded in development environments to prevent your application throwing errors when autoload-dev packages like Faker and so are are not installed on production systems.

Using seeders

Optional; requires a module service provider

Seeders can be placed in your default /database/seeds directory or per module in YourModule/database/seeds. They are not namespaced and available globally, so watch out for identically named seeders across modules.

Using translations

Optional; requires a module service provider

Translations are kept in the /resources/lang or YourModule/resources/lang module directory. If you use the latter and keep them within the module, remember to prefix your translation keys with the snake cased module name (as if you were using a package) to retrieve the correct value:

Using views

Optional; requires a module service provider

As with translations, views follow the same pattern. You can keep them in the default /resources/views directory or in YourModule/resources/views. To use a view or include a partial, prefix the path with your snake cased module name:

Simplified polymorphic model type mapping

Optional; requires a module service provider

Instead of manually calling Relation::morphMap([]), you can map the polymorphic types or aliases of your Eloquent models by defining a morph map array in your module service provider:

Be sure to check out my other auto morph map package to automatically alias all your models without writing any code.

Simplified event listener registration

Optional; requires a module service provider

In the same way you can define a morph map in your module service provider, you can also define a list of event listeners or subscribers:

Automatic router mapping

Optional; requires a module service provider

Handling and organizing routes in a medium or large Laravel application can get messy quite fast. To counter that ever-expanding list of routes, this package provides support for sebastiaanluca/laravel-router to automatically register and map your contextual routes and routers:

Automatic service provider registration

Optional; requires a module service provider

To counter a module's service provider from getting out of control in terms of lines of code and methods, it might be best to split it into multiple other service providers that each have a single task. For instance, a ModuleEventProvider can be used to map all events of the module, while another ModuleRouteProvider can contain all the routes or routers to easily map upon application boot.

Of course those providers will still need to be registered. You can do so manually in the module's default provider, but also automatically using a list:

Package configuration

To copy the package's configuration file to your root config directory, run:

Then choose laravel-module-loader (configuration) from the list.

Runtime autoloading

This package supports runtime autoloading of all modules and their non-namespaced database directories. Basically it reads and loads your modules during framework boot, instead of relying on Composer to autoload your module's classes before.

Set runtime_autoloading in the package's configuration to true and remove your module entries from composer.json's autoload sections.

Note that there are some trade-offs to enabling this:

Module directories

By default, only the modules directory in your root project is scanned for modules. By altering or extending this list, you can further organize the directory or directories your modules reside in however you like.

For instance you can group personal and work-related modules in their separate folders for reusability across projects.

Development environments

The development environments configuration option allows you to change the list of environments…

The app environment is read from your .env file through the Laravel application config.

License

This package operates under the MIT License (MIT). Please see LICENSE for more information.

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

Contributing

Please see CODE OF CONDUCT for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

About

My name is Sebastiaan and I'm a freelance back-end developer specializing in building custom Laravel applications. Check out my portfolio for more information, my blog for the latest tips and tricks, and my other packages to kick-start your next project.

Have a project that could use some guidance? Send me an e-mail at [email protected]!


All versions of laravel-module-loader with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
laravel/framework Version ^8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package sebastiaanluca/laravel-module-loader contains the following files

Loading the files please wait ....