This is lightweight implemntation of multidomain setup for Laravel. With this package you can create domains, and have automatically per domain filtered models with very easy implementation.
You can install the package via composer:
composer require vdrnoyan/per_domain_models_filter
Publish migrations
php artisan vendor:publish --provider="Vdrnoyan\TenantModelFilter\TenantModelFilterServiceProvider"
Run migration
php artisan migrate
You have to set up domain which opens you laravel installation. For this you may run following for your local valet setup;
valet link mydomain
You have to create domain entry in your database.
use Vdrnoyan\TenantModelFilter\Domain;
Domain::create(['domain'=>'mydomain.test', 'data'=>NULL]);
Add PerDomainFilterable trait to you filtrable model.
namespace \App;
use Illuminate\Database\Eloquent\Model;
use Vdrnoyan\TenantModelFilter\PerDomainFilterable;
class Item extends Model
{
use PerDomainFilterable;
}
Now you can create any item of your model by sending request to the domain you just set up, and the relation between this model and domain will be established. Use following code to retrive domain specific items from database.
$items = App\Item::all()->onlyForThisDomain();
Beside the Collection filter you have also Eloquent query scope filter to use with methods like paginate. 'withDomain' method will ensure you have loaded only domain relevant items in your page, instead of filtering it after load, like it does Collection's 'onlyForThisDomain' method.
Item::withDomain()->paginate(2);
Domain specific items can be also retrieved from current, or any domain models.
currentDomain()->filterOwn(Item::class)->get();
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
This package was generated using the Laravel Package Boilerplate.