Download the PHP package bvharen/laravel-subdomain without Composer
On this page you can find all versions of the php package bvharen/laravel-subdomain. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-subdomain
Associate models to dynamic subdomains in laravel
Easily setup dynamic subdomains registered to models on your application
e.g company1.myapp.com
- Intallation
- Config
- Usage
- Facade
- Middleware
Installation
You can install this package via composer by
*In Laravel 5.5 and below add this to your providers and aliases array
Then run php artisan vendor:publish
to publish the configuration file
Config
The config/subdomains.php
file:
Once you have published the package, you can then set the configuration to your application's setup
Usage
After setting up your routes to catch subdomains e.g
Make sure all controller assigned to subdomains extend the \kofoworola\Subdomains\Controller\SubdomainController
class:
The parent controller automatically removes the subdomain parameter from list of paremeters so you don't have to add it to you parameter list everytime you want to get another parameter
Facade
Using the kofoworola\Subdomains\Facade\Subdomains
facade you can access helper functions:
Getting the name of the parameter
Use Subdomains::name()
to get the name of the subdomain parameter
Getting the value of the subdomain
Use Subdomains::value()
to get the value of the subdomain parameter
Getting the owner of the subdomain
Use Subdomains::owner()
to get the model instance that owns the current subdomain
Checking if the user has access to the subdomain
Subdomains::ownsModel($user = null)
returns true or false depending on whether the user has access to the subdomain
If no user is passed the current logged in user is used
Getting a subdomain route
Can be used to generate a subdomain link
Middleware
You can also add the \kofoworola\Subdomains\Middleware\HasSubdomain
middleware to your routes.
Firstly register it in your Kernel
:
Then add it to your routes:
The middleware will take care of verifying if:
- The subdomain exists
- The current user has access to the subdomain