PHPackages                             omergy/laravel-apps - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. omergy/laravel-apps

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

omergy/laravel-apps
===================

Laravel multi-application support.

0.11.0(11mo ago)03.5k—8.3%1MITPHPPHP ^8.2

Since Oct 2Pushed 11mo agoCompare

[ Source](https://github.com/omergy/laravel-apps)[ Packagist](https://packagist.org/packages/omergy/laravel-apps)[ Docs](https://github.com/ElfSundae/laravel-apps)[ RSS](/packages/omergy-laravel-apps/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (5)Used By (0)

Laravel Apps
============

[](#laravel-apps)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b4e3e12215690bbccd287b24b3d30ab2744b8df15f21572939cb93595111ee92/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656c6673756e6461652f6c61726176656c2d617070732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/elfsundae/laravel-apps)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![tests](https://github.com/ElfSundae/laravel-apps/actions/workflows/tests.yml/badge.svg)](https://github.com/ElfSundae/laravel-apps/actions/workflows/tests.yml)[![StyleCI](https://camo.githubusercontent.com/1e9f13ae280ca917b8cb491d358c717218807715fa9eadc6746781166c82a613/68747470733a2f2f7374796c6563692e696f2f7265706f732f3131323630373934372f736869656c64)](https://styleci.io/repos/112607947)[![SymfonyInsight Grade](https://camo.githubusercontent.com/ff2c4355bd4cf25096d856045ef84ca604623a7ff48cc8f0567490c55ca04c3b/68747470733a2f2f696d672e736869656c64732e696f2f73796d666f6e792f692f67726164652f30646361396563372d353763362d343136322d393761352d3864306133313539383434643f7374796c653d666c61742d737175617265)](https://insight.symfony.com/projects/0dca9ec7-57c6-4162-97a5-8d0a3159844d)[![Quality Score](https://camo.githubusercontent.com/22831dcc0afdf01f8122be90ad7b7cd2d6fdd8ad3b41336c76bf431efbf3a736/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f456c6653756e6461652f6c61726176656c2d617070732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/ElfSundae/laravel-apps)[![Code Coverage](https://camo.githubusercontent.com/2f858329313fec5cb502a13b3dfc27766d1e1af323d58412ce71c39f7e888033/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f456c6653756e6461652f6c61726176656c2d617070732f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/ElfSundae/laravel-apps/?branch=master)[![Total Downloads](https://camo.githubusercontent.com/63fba9f635356a3d0b336a81999cbb82fdda973ed9deda528a06b73466f9db43/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f656c6673756e6461652f6c61726176656c2d617070732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/elfsundae/laravel-apps)

This package provides basic support for Laravel multi-application.

- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)
    - [Obtain Application Manager Instance](#obtain-application-manager-instance)
    - [Retrieve Application URL Configuration](#retrieve-application-url-configuration)
    - [Determine The Current Application Identifier](#determine-the-current-application-identifier)
    - [Selectively Register Service Providers](#selectively-register-service-providers)
    - [Define Application Routes](#define-application-routes)
    - [Generate URL](#generate-url)
    - [Custom Root URL For asset() Helper](#custom-root-url-for-asset-helper)
    - [Extend Application Manager](#extend-application-manager)
- [Testing](#testing)
- [License](#license)

Installation
------------

[](#installation)

You can install this package using the [Composer](https://getcomposer.org) manager:

```
$ composer require elfsundae/laravel-apps
```

For earlier Laravel than v5.5, you need to register the service provider manually:

```
ElfSundae\Apps\AppsServiceProvider::class,
```

Then publish the [configuration file](config/apps.php) to your `config` directory:

```
$ php artisan vendor:publish --tag=laravel-apps
```

Configuration
-------------

[](#configuration)

The `url` configuration option defines the root URL of each application:

```
'url' => [
    'web' => 'https://example.com',
    'admin' => 'https://example.com/admin',
    'mobile' => 'https://m.example.com',
    'api' => 'https://api.example.com',
    'assets' => 'https://assets.foo.net',
],
```

The `providers` array lists the class names of service providers for each application, you may configure this to [selectively register service providers](#selectively-register-service-providers).

The `config` option may be used to override the default configurations for each application. Additionally, you may wish to put all of your application defaults in one place instead of editing separate configuration files, just put them in the `default` key:

```
'config' => [

    'default' => [
        'app.timezone' => 'Asia/Shanghai',
        'app.log' => env('APP_LOG', 'daily'),
        'app.log_max_files' => 50,
        'filesystems.disks.public.url' => env('APP_URL_ASSETS', env('APP_URL')).'/storage',

        'debugbar.options.auth.show_name' => false,
        'debugbar.options.route.label' => false,
    ],

    'admin' => [
        'auth.defaults' => [
            'guard' => 'admin',
            'passwords' => 'admin_users',
        ],
        'filesystems.default' => 'public',
        'session.domain' => env('SESSION_DOMAIN_ADMIN', null),
    ],

    'api' => [
        'auth.defaults.guard' => 'api',
        'filesystems.default' => 's3',
    ],

],
```

Usage
-----

[](#usage)

### Obtain Application Manager Instance

[](#obtain-application-manager-instance)

You may obtain the application manager instance using the `Apps` facade, the `apps()` helper function or injecting the `ElfSundae\Apps\AppManager` dependency.

### Retrieve Application URL Configuration

[](#retrieve-application-url-configuration)

```
use ElfSundae\Apps\Facades\Apps;

// Get all application URLs
Apps::urls();

// Get all application identifiers
apps()->ids();

// Get URL root for the assets app
apps()->root('assets');

// Get URL domain for the api app
apps()->domain('api');

// Get URL prefix for the admin app
apps()->prefix('admin');
```

### Determine The Current Application Identifier

[](#determine-the-current-application-identifier)

The application identifier to the current request can be determined via the `id` method on the app manager, or using the corresponding `app_id` helper function:

```
$appId = Apps::id();

$appId = app_id();
```

You may also pass arguments to the `id` method to check if the current application identifier matches a given value. The method will return `true` if the identifier matches any of the given values:

```
if (Apps::id('admin')) {
    // Currently requesting admin app
}

if (app_id('web', 'admin')) {
    // Currently requesting either web app OR admin app
}
```

### Selectively Register Service Providers

[](#selectively-register-service-providers)

Instead of adding all service providers to the `config/app.php` file, you may want to selectively register service providers for certain sub applications to optimize performance. To do so, simply list the providers to the `providers` array in the `config/apps.php` configuration file:

```
'providers' => [

    'admin' => [
        Rap2hpoutre\LaravelLogViewer\LaravelLogViewerServiceProvider::class,
        Yajra\DataTables\DataTablesServiceProvider::class,
        App\Providers\AdminServiceProvider::class,
    ],

    'api' => [
        App\Providers\ApiServiceProvider::class,
    ],

],
```

⚠️ If your application runs on Laravel 5.5+ which support [package discovery](https://laravel.com/docs/5.5/packages#package-discovery), you also need to disable discovery for the optional packages in the `composer.json` file:

```
"extra": {
    "laravel": {
        "dont-discover": [
            "rap2hpoutre/laravel-log-viewer",
            "yajra/laravel-datatables-oracle"
        ]
    }
}
```

> Don't worry about the [deferred service providers](https://laravel.com/docs/providers#deferred-providers), as the deferred providers are only loaded when needed.

### Define Application Routes

[](#define-application-routes)

The `routes` method on the app manager helps you define route group for each application. In general, you will call it in the `map` method of your `RouteServiceProvider`:

```
class RouteServiceProvider extends ServiceProvider
{
    protected $namespace = 'App\Http\Controllers';

    /**
     * Define the routes for the application.
     *
     * @return void
     */
    public function map()
    {
        apps()->routes();
    }
}

```

The route files named with the application identifiers in the `routes` directory will be automatically loaded, such as `routes/web.php`, `routes/admin.php`.

By default, the `routes` method will assign the existing middleware group named with the application identifier or `web` to the route group, and the namespace applied to your controller routes will be `StudlyCase` of the application identifier.

For example, `apps()->routes()` is equivalent to:

```
// web: https://example.com
Route::group([
    'domain' => 'example.com',
    'middleware' => 'web',
    'namespace' => $this->namespace.'\Web',
], function ($router) {
    require base_path('routes/web.php');
});

// api: https://api.example.com
Route::group([
    'domain' => 'api.example.com',
    'middleware' => 'api',
    'namespace' => $this->namespace.'\Api',
], function ($router) {
    require base_path('routes/api.php');
});

// admin: https://example.com/admin
Route::group([
    'domain' => 'example.com',
    'prefix' => 'admin',
    'middleware' => 'web', // suppose if the "admin" middleware group does not exist
    'namespace' => $this->namespace.'\Admin',
], function ($router) {
    require base_path('routes/admin.php');
});

// ...
```

Of course, you are free to specify any route attributes:

```
apps()->routes([
    'web' => [
        'namespace' => $this->namespace,
    ],
    'admin' => [
        'middleware' => ['web', 'admin.ip'],
        'as' => 'admin.',
        'where' => [
            'id' => '[0-9]+',
        ],
    ],
]);
```

In addition to an array, you can pass a Closure to the `routes` method:

```
apps()->routes(function ($id, $apps) {
    return ['as' => $id.'.'];
});
```

### Generate URL

[](#generate-url)

You can use the `url` method or the corresponding `app_url` helper function to generate an absolute URL to a path for a specified application:

```
apps()->url('admin', 'user', [$user]); // https://example.com/admin/user/123

app_url('api', 'posts'); // https://api.example.com/posts
```

The `asset` method generates a URL with the root URL of the `assets` application:

```
apps()->asset('js/app.js'); // https://assets.foo.net/js/app.js
```

### Custom Root URL For asset() Helper

[](#custom-root-url-for-asset-helper)

The Laravel built-in `URL::asset` method or the corresponding `asset`, `secure_asset` helper functions are designed to generate URL for the application assets. In most applications, we will probably specify a cookie-free domain or use CDN for the assets, however we can not set custom root URL for these built-in assets methods, and for now there is no elegant way to extend the core `UrlGenerator`.

You may use `URL::assetFrom`, `Apps::asset`, or a custom helper function to generate assets URLs, but it is awfully boring to replace all `asset()` calls to your own assets method for the third-party packages. Maybe a better workaround is overwriting the built-in `asset` helper: define your `asset` function before including the Composer autoloader file, in your `public/index.php` file:

```
function asset($path, $secure = null)
{
    return apps()->asset($path, $secure);
}

require __DIR__.'/../vendor/autoload.php';
```

This package ships with an [`asset.php`](asset.php) file you may include to use the root URL of the `assets` application for the `asset()` helper:

```
require __DIR__.'/../vendor/elfsundae/laravel-apps/asset.php';

require __DIR__.'/../vendor/autoload.php';
```

> FYI, related PR [laravel/framework#22372](https://github.com/laravel/framework/pull/22372).

### Extend Application Manager

[](#extend-application-manager)

The [`AppManager`](src/AppManager.php) class is macroable, that means you can use the `macro` method to extend it:

```
Apps::macro('route', function ($name, $parameters = []) {
    return URL::route($this->id().'.'.$name, $parameters);
});
```

Testing
-------

[](#testing)

```
$ composer test
```

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT License](LICENSE.md).

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance50

Moderate activity, may be stable

Popularity23

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.9% of commits — single point of failure

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.

###  Release Activity

Cadence

Every ~238 days

Total

2

Last Release

356d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/98457067?v=4)[OMERGY](/maintainers/omergy)[@omergy](https://github.com/omergy)

---

Top Contributors

[![ElfSundae](https://avatars.githubusercontent.com/u/526008?v=4)](https://github.com/ElfSundae "ElfSundae (233 commits)")[![omergy](https://avatars.githubusercontent.com/u/98457067?v=4)](https://github.com/omergy "omergy (5 commits)")

---

Tags

laravelassetsapplicationmultidomainmultiple

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/omergy-laravel-apps/health.svg)

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

###  Alternatives

[elfsundae/laravel-apps

Laravel multi-application support.

8410.5k](/packages/elfsundae-laravel-apps)[jasonlewis/resource-watcher

Simple PHP resource watcher library.

221145.8k14](/packages/jasonlewis-resource-watcher)[fisharebest/laravel-assets

Asset management for Laravel

208.1k](/packages/fisharebest-laravel-assets)[efficiently/jquery-laravel

This package provides jQuery and the jQuery-ujs driver for your Laravel &gt;= 6 application.

1311.0k1](/packages/efficiently-jquery-laravel)[netinternet/logicboxes

Laravel logicboxes package

151.5k](/packages/netinternet-logicboxes)

PHPackages © 2026

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