Download the PHP package elfsundae/laravel-apps without Composer
On this page you can find all versions of the php package elfsundae/laravel-apps. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download elfsundae/laravel-apps
More information about elfsundae/laravel-apps
Files in elfsundae/laravel-apps
Package laravel-apps
Short Description Laravel multi-application support.
License MIT
Homepage https://github.com/ElfSundae/laravel-apps
Informations about the package laravel-apps
Laravel Apps
This package provides basic support for Laravel multi-application.
- Installation
- Configuration
- Usage
- Obtain Application Manager Instance
- Retrieve Application URL Configuration
- Determine The Current Application Identifier
- Selectively Register Service Providers
- Define Application Routes
- Generate URL
- Custom Root URL For asset() Helper
- Extend Application Manager
- Testing
- License
Installation
You can install this package using the Composer manager:
For earlier Laravel than v5.5, you need to register the service provider manually:
Then publish the configuration file to your config
directory:
Configuration
The url
configuration option defines the root URL of each application:
The providers
array lists the class names of service providers for each application, you may configure this to 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:
Usage
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
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:
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:
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:
:warning: If your application runs on Laravel 5.5+ which support package discovery, you also need to disable discovery for the optional packages in the composer.json
file:
Don't worry about the deferred service providers, as the deferred providers are only loaded when needed.
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
:
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:
Of course, you are free to specify any route attributes:
In addition to an array, you can pass a Closure to the routes
method:
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:
The asset
method generates a URL with the root URL of the assets
application:
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:
This package ships with an asset.php
file you may include to use the root URL of the assets
application for the asset()
helper:
FYI, related PR laravel/framework#22372.
Extend Application Manager
The AppManager
class is macroable, that means you can use the macro
method to extend it:
Testing
License
This package is open-sourced software licensed under the MIT License.