PHPackages                             isemenkov/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. isemenkov/laravel-modules

AbandonedArchivedLibrary[Framework](/categories/framework)

isemenkov/laravel-modules
=========================

laravel modules library

210PHP

Since Dec 29Pushed 5y ago1 watchersCompare

[ Source](https://github.com/isemenkov/laravel-modules)[ Packagist](https://packagist.org/packages/isemenkov/laravel-modules)[ RSS](/packages/isemenkov-laravel-modules/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependenciesVersions (1)Used By (0)

laravel-modules
===============

[](#laravel-modules)

A simple package for working with template modules.

### Table of contents

[](#table-of-contents)

- [What is?](#what-is)
    - [Solution](#solution)
    - [Module structure](#module-structure)
    - [Register module](#register-module)
- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)

### What is?

[](#what-is)

#### Solution

[](#solution)

laravel-modules is a package designed to separate the logic of an individual component from the general logic of the application. It allows to create and manage separate logical blocks (modules). Each module encapsulates methods for managing render logic, access control, caching, etc.

#### Module structure

[](#module-structure)

Each module is standard php class with several optional methods.

```
namespace App\Modules\TestModule;

class TestModule {

   /**
     * Return current module template position label string.
     * If function isn't exists as position label uses lowercase module class
     *   name.
     * If return callback function then ModulesManager call it to resolve
     *   module position.
     *
     * @param void
     * @return string|callable Position label | Callback function.
     */
    public function position() {
        return "module.position";
    }

   /**
     * Return current module sort priority value.
     * This value is used to sort multiples modules registered in one position.
     * If function isn't exists priority sets as zero.
     * If return callback function then ModulesManager call it to resolve
     *   module priority weight.
     *
     * @param void
     * @return integer|callable Sort module priority weight | Callback function.
     */
    public function priority() {
        return -1;
    }

   /**
     * Return current module needs permissions.
     * If return bool value then on true module is rendered, on false none.
     * If return value type is string it is a permission access to render.
     * If return callback function then ModulesManager call it to resolve
     *   permissions.
     * If function isn't exists module render always.
     *
     * @param void
     * @return string|callable Module permissions string | Callback function
     */
    public function permission() {
        return "module.permission";
    }

   /**
     * Current module caching strategy.
     * If return bool value then on true module cached always. As a cache key
     *   uses lowercase module name. On false module newer cached.
     * If return value type is string it is uses as cache key.
     * If return callback function then ModulesManager call it to resolve
     *   caching strategy.
     *
     * @return bool|string|callable Module cached stategy.
     */
    public function cache() {
        return "module.cache_key";
    }

   /**
     * Current module cache time.
     * If return bool value then on true module cached forever. On false module
     *   newer cached.
     * Return value for cache timeout in seconds.
     * If return callback function then ModulesManager call it to resolve
     *   cache time.
     *
     * @param void
     * @return bool|integer|callable
     */
    public function cacheTime() {
        return 3600;
    }

   /**
     * Render current module.
     * If function exists it is uses to render current module.
     *
     * @param mixing Template render arguments.
     * @return string|serializable Rendered view.
     */
    public function render($args = null) {
        return View::make("module.view");
    }
}
```

#### Register module

[](#register-module)

Each module must be registered before use. You can use several ways for this.

- Set module class object.

```
public function index(ModulesManager $manager) {
    $manager->registerModule([
        new TestModule($construct_args),
        /* Register as many modules as you need */
    ]);

    return View::make('frontend');
}
```

- Set full module string class name

```
public function index(ModulesManager $manager) {
    $manager->registerModule([
        TestModule::class,
    ]);

    return View::make('frontend');
}
```

To pass arguments to a constructor, pass an array, the first element of which will be the class name, and the second element will be arguments to the constructor.

```
public function index(ModulesManager $manager) {
    $manager->registerModule([
        [TestModule::class, $construct_args],
    ]);

    return View::make('frontend');
}
```

If you need to pass several parameters to the constructor, wrap them in an array.

```
public function index(ModulesManager $manager) {
    $manager->registerModule([
        [TestModule::class, [$construct_arg1, $consruct_arg2]],
    ]);

    return View::make('frontend');
}
```

Add the third element of the array to pass arguments to the render method.

```
public function index(ModulesManager $manager) {
    $manager->registerModule([
        [TestModule::class, $consruct_args, $render_args],
    ]);

    return View::make('frontend');
}
```

### Requirements

[](#requirements)

- Laravel 5+
- PHP 5.3.7+

### Installation

[](#installation)

Require this package with composer.

```
composer require isemenkov/laravel-modules

```

### Usage

[](#usage)

```
namespace App\Http\Controllers;

use Illuminate\Support\Facades\View;
use isemenkov\Modules\ModulesManager;
use App\Modules\TestModule;

class TestController extends Controller {

    public function index(ModulesManager $manager) {
        $manager->registerModule([
            TestModule::class,
        ]);

        return View::make('frontend');
    }
}
```

```

>

      @module(module.position)

```

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity31

Early-stage or recently created project

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/e4afb9ba2fd17423261becccc3ba4bbd9f15b669a7415e203021f81ad4df0e5c?d=identicon)[isemenkov](/maintainers/isemenkov)

---

Tags

laravellaravel-package

### Embed Badge

![Health badge](/badges/isemenkov-laravel-modules/health.svg)

```
[![Health](https://phpackages.com/badges/isemenkov-laravel-modules/health.svg)](https://phpackages.com/packages/isemenkov-laravel-modules)
```

###  Alternatives

[laravel/socialite

Laravel wrapper around OAuth 1 &amp; OAuth 2 libraries.

5.7k104.3M831](/packages/laravel-socialite)[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k38.6M289](/packages/laravel-dusk)[pinguo/php-msf

Pinguo Micro Service Framework For PHP

1.7k4.2k](/packages/pinguo-php-msf)[nineinchnick/edatatables

Grid widget for the Yii Framework, wrapper for the DataTables jQuery plugin

173.2k](/packages/nineinchnick-edatatables)[link-cloud/fast-hyperf

LinkCloud Fast Hyperf

241.2k1](/packages/link-cloud-fast-hyperf)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
