Package Data | |
---|---|
Maintainer Username: | Zonneplan |
Package Create Date: | 2019-09-09 |
Package Last Update: | 2024-03-18 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-23 03:14:51 |
Package Statistics | |
---|---|
Total Downloads: | 83,337 |
Monthly Downloads: | 1,663 |
Daily Downloads: | 41 |
Total Stars: | 24 |
Total Watchers: | 9 |
Total Forks: | 1 |
Total Open Issues: | 1 |
The zonneplan/laravel-module-loader
package provides an easy to use module loader
which can be used to modulize your project.
First install the package, see the installation section.
Modules
in the app directory.User
.UserServiceProvider
which extends our abstract Module
class.getModuleNamespace()
like:namespace Modules\User;
use Zonneplan/ModuleLoader/Module;
class UserServiceProvider extends Module
{
public function getModuleNamespace(): string
{
return 'user';
}
}
UserServiceProvider
in the config/app.php
file.'providers' => [
Modules\User\UserServiceProvider::class
]
The expected structure is seen below. Most of it is optional.
app
├── Modules
├──MyModule
├──Config
├──Console
├──Database
├──Factories
├──Migrations
├──Exceptions
├──Http
├──Controllers
├──Middleware
├──Requests
├──Resources
├──Resources
├──lang
├──views
├──Routes
├──web.php
├──api.php
├──channels.php
├──console.php
├──MyModuleServiceProvider.php
├──tests
To access a view from a module it will look like 'my-module::path.to.view'
For example:
// In a controller
view('user::index');
// In a blade file
@include('user::index');
@include('user::partials.form');
To register policies overwrite the $policies
variable in the ServiceProvider of your module
For example:
protected $policies = [
MyModel::class => MyModelPolicy::class,
];
To register middleware overwrite the $middleware
variable in the ServiceProvider of your module
For example:
protected $middleware = [
'my-middleware' => MyMiddleware::class,
];
To register events & listeners overwrite the $listen
variable in the ServiceProvider of your module
For example:
protected $listen = [
MyEvent::class => [
MyListener::class
],
];
To register event subscribers overwrite the $subscribe
variable in the ServiceProvider of your module
For example:
protected $subscribe = [
MySubscriber::class
];
All modules will by default try to load all route files in the Routes
folder.
Any of the following files will be auto loaded:
routes.php
api.php
web.php
This package requires at least Laravel 6 or higher, PHP 7.2 or higher
composer require zonneplan/laravel-module-loader
The package will automatically register itself.
Register the namespace: "Modules\\": "app/Modules"
in composer.json
like:
"autoload": {
"psr-4": {
"App\\": "app/",
"Modules\\": "app/Modules"
},
...