vdrnoyan/per_domain_models_filter

Simple per domain model filtering package.

v0.1 2020-06-30 18:10 UTC

This package is auto-updated.

Last update: 2024-09-20 00:28:33 UTC


README

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.

Installation

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

Usage

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();

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email v.drnoyan@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Laravel Package Boilerplate

This package was generated using the Laravel Package Boilerplate.