PHPackages                             thomasderooij/laravel-modules - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. thomasderooij/laravel-modules

ActiveLibrary[Framework](/categories/framework)

thomasderooij/laravel-modules
=============================

Laravel framework modules kit.

2.0.1(3y ago)52432[1 PRs](https://github.com/thomasderooij/laravel-modules/pulls)MITPHPPHP ^8.1

Since Dec 29Pushed 3y ago1 watchersCompare

[ Source](https://github.com/thomasderooij/laravel-modules)[ Packagist](https://packagist.org/packages/thomasderooij/laravel-modules)[ RSS](/packages/thomasderooij-laravel-modules/feed)WikiDiscussions master Synced yesterday

READMEChangelog (10)Dependencies (5)Versions (29)Used By (0)

Laravel Modules
---------------

[](#laravel-modules)

[![Build Status](https://camo.githubusercontent.com/56cd6157fa0f1d12eac5bb63e1168b617b5c6bc2fa2ec5f4caf055588aaf2adb/68747470733a2f2f7472617669732d63692e636f6d2f74686f6d61736465726f6f696a2f6c61726176656c2d6d6f64756c65732e7376673f746f6b656e3d696863375a674275464b473362626d6764674b43266272616e63683d76302e312e30)](https://travis-ci.com/thomasderooij/laravel-modules.svg?token=ihc7ZgBuFKG3bbmgdgKC&branch=v0.1.0)[![License](https://camo.githubusercontent.com/cb7ef53f1cf81fbffd5fc0293c58ed62fc4187574869d755b1f296176c6adb88/68747470733a2f2f706f7365722e707567782e6f72672f74686f6d61736465726f6f696a2f6c61726176656c2d6d6f64756c65732f6c6963656e73652e737667)](https://packagist.org/packages/thomasderooij/laravel-modules)

Install
-------

[](#install)

Require this package with composer using the following command:

```
composer require thomasderooij/laravel-modules
```

Docs
----

[](#docs)

This package enables you to use the Laravel framework with separate modules for code that can be disabled and have dependencies on other modules. A workbench is provided to keep track of the module you're currently working on, and all command, such as "make:controller" apply to the module currently in your workbench. Each module has all functionality the vanilla Laravel has, and has service providers which are included in the project via a composite provider.

### Getting started

[](#getting-started)

To get started, run the following commands:

```
php artisan module:init
php artisan migrate
```

### Commands

[](#commands)

To manage your modules, you can use the following commands are provided:

```
php artisan module:new
```

This creates a new module in your modules directory, and sets it to your workbench. It will also ask about its dependencies. If your module, called Users, is dependent on another module, called Auth, you can specify this here, and it will take this into account when running database migrations.

```
php artisan module:delete
```

This deletes a module and all of the code it contains. Only use this when you are sure you don't need the code in this module. If you are unsure, use the deactivate command.

```
php artisan module:deactivate
```

This deactivates a module. This means the code will remain intact, but the commands, controllers and routes are not recognised, and as far as the software is concerned, do not exist.

```
php artisan module:activate
```

This reactivates a deactivated a module.

```
php artisan module:set
```

This sets one of your modules to your workbench. This is set in your local cache, and will expire in 1 week.
The only advantage to this is when you call a make command, it will apply to the module in your workbench. To apply this to another module, add --module=your-module-here-case-insensitive and it will apply it to whatever module you wish, as long as it exists

```
php artisan module:unset
```

This clears your workbench

```
php artisan module:check
```

This tells you which module, if any, is currently in your workbench

```
php artisan module:add-dependency
```

This allows you to add dependencies so your module, indicating your module cannot function without the upstream module. Circular references are not allowed. E.g., Module Auth can not depend on User as long as module User is dependent on Auth. If this is the case, you should probably consider making this just 1 module, instead of 2. This command will only show you modules that are not downstream of your current module.

```
php artisan module:delete-dependency
```

This is the inverse of the add-dependency command. It shows you which dependencies your module has, and it allows you to remove any or all of these.

### Directory structure

[](#directory-structure)

When creating a new module, your directory structure will look as follow:

```
.
├── app
├── bootstrap
├── config
├── database
├── modules
│   └── YourModule
│   │   ├── Console
│   │   │   └── Kernel.php
│   │   ├── Http
│   │   │   └── Controllers
│   │   │       ├── Controller.php
│   │   ├── Providers
│   │   │   ├── AuthServiceProvider.php
│   │   │   ├── BroadcastServiceProvider.php
│   │   │   ├── EventServiceProvider
│   │   │   └── RouteServiceProvider
│   │   └── routes
│   │       ├── api.php
│   │       ├── console.php
│   │       └── web.php
│   └── .tracker
├── public
├── resources
├── routes
├── storage
├── tests
└── vendor

```

The .tracker file keeps track of the modules you have and their dependencies.
All directories you're not seeing, like Database, Events, Jobs, Exceptions etc. will be created when the make command is invoked.
If you're having issues with PHPUnit, make sure you add your modules test directory to your phpunit.xml file.

### Laravel Commands

[](#laravel-commands)

#### Make

[](#make)

All the make commands will apply to the module in your workbench and can be overwritten by using --module option. If there is no module in your workbench and the --module option is not used, the commands will display vanilla Laravel behaviour. To explicitly refer to the vanilla Laravel directories, you can use the --module=vanilla option.

For any models, when creating the model using the make:model command, the HasFactory trait refers to this library's trait. Should your model not find a factory, check if the model refers to the correct trait.

#### Migrate

[](#migrate)

The migrate command looks at your module dependencies, and migrates them based on that. So make sure your downstream migrations don't reference your upstream migrations, because that would be trouble.
Both the migrate and the migrate:fresh commands have a --modules option, in case you don't want to use your dependencies and will migrate the modules in the order they are provided in. The modules should be comma separated, as displayed below

```
php artisan migrate
