Giter Site home page Giter Site logo

rinvex / laravel-tenants Goto Github PK

View Code? Open in Web Editor NEW
82.0 3.0 15.0 425 KB

Rinvex Tenantable is a contextually intelligent polymorphic Laravel package, for single db multi-tenancy. You can completely isolate tenants data with ease using the same database, with full power and control over what data to be centrally shared, and what to be tenant related and therefore isolated from others.

License: MIT License

PHP 100.00%
php laravel multi-tenancy

laravel-tenants's Issues

I cant get tenant from User Model and make this work with Observer

Hello, first thanks for this package.

I have this scenario:

i Have this Middleware: \App\Http\Middleware\Tenant::class, i get tenant id from user Model

public function handle(Request $request, Closure $next)
{
    if( Schema::hasTable('tenants') ) {
        if (auth()->check()) {
            $tenant = app('rinvex.tenants.tenant')->find(backpack_user()->tenants());
        } else {
            $tenant = null;
        }

        app()->singleton('request.tenant', fn() => $tenant); // setear null si se quiere ver todo
    }

    return $next($request);
}

This work for almost everything, except when i use Observer, is look like when Observer is add this make laravel execute models before middleware, and thats make ignore the scope.

How can i make this: get id from user model and make this package work with observer?

Thanks in advance.

Support Laravel 11

Hey there,

thank you very much for this great package.

Unfortunately there are version conflicts when trying to install the package in Laravel 11.

Steps to reproduce

  1. Install current Laravel version (in my case 11.2.0)
  2. run composer require rinvex/laravel-tenants

The following error message shows up

Composer could not detect the root package (laravel/laravel) version, defaulting to '1.0.0'. See https://getcomposer.org/root-version
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Nothing to install, update or remove
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi

   Error

  Call to undefined method Rinvex\Tenants\Providers\TenantsServiceProvider::publishesConfig()

  at vendor/rinvex/laravel-tenants/src/Providers/TenantsServiceProvider.php:56
     52▕      */
     53▕     public function boot()
     54▕     {
     55▕         // Publish Resources
  ➜  56▕         $this->publishesConfig('rinvex/laravel-tenants');
     57▕         $this->publishesMigrations('rinvex/laravel-tenants');
     58▕         ! $this->autoloadMigrations('rinvex/laravel-tenants') || $this->loadMigrationsFrom(__DIR__.'/../../database/migrations');
     59▕
     60▕         // Resolve active tenant

      +7 vendor frames

  8   [internal]:0
      Illuminate\Foundation\Application::Illuminate\Foundation\{closure}()
      +6 vendor frames

  15  artisan:13
      Illuminate\Foundation\Application::handleCommand()

Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1

When laravel/framework version 11 is installed, rinvex/laravel-tenants:8.1.0 instead of rinvex/laravel-tenants:8.1.2 is pulled in. This is apparently because rinvex/laravel-tenants:8.1.2 has symfony/console:^6.2.0 as dependency which seems to conflict with the requirements for Laravel 11.

A fix would be highly appreciated.

Dependabot can't resolve your PHP dependency files

Dependabot can't resolve your PHP dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Your requirements could not be resolved to an installable set of packages.
  Problem 1
    - felixkiss/uniquewith-validator 3.4.0 requires illuminate/support ^5.5|^6.0|^7.0 -> found illuminate/support[v5.5.0, ..., 5.8.x-dev, v6.0.0, ..., 6.x-dev, v7.0.0, ..., 7.x-dev] but it conflicts with your root composer.json require (^8.0.0 || ^9.0.0).
    - rinvex/laravel-support v5.0.0 requires felixkiss/uniquewith-validator ^3.4.0 -> satisfiable by felixkiss/uniquewith-validator[3.4.0].
    - Root composer.json requires rinvex/laravel-support ^5.0.0 -> satisfiable by rinvex/laravel-support[v5.0.0].

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

Creating tenant entries in seeders do not respect tenant supplied

I don't know if I am doing something wrong.

        $tenants = app('rinvex.tenants.tenant')->all();
        foreach ($tenants as $tenant) {
               $user = User::create([
                   ...
            ]);
            $user->attachTenants($tenant);
            $user->update();
        }

Outside the request cycle attachTenant($tenant) does not work.

This does work:

        foreach ($tenants as $tenant) {
               app()->bind('request.tenant', fn() => $tenant);
               $user = User::create([
                   ...
            ]);
            $user->attachTenants($tenant);
            $user->update();
        }

Is this how this module is intended to work?

Unable to install on laravel 7 and php 7.3

I set up a new project and was unable to install the package. here's what I'm getting

`composer require rinvex/laravel-tenants
Using version ^3.0 for rinvex/laravel-tenants
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

Problem 1
- Conclusion: remove laravel/framework v7.0.0
- Conclusion: don't install laravel/framework v7.0.0
- rinvex/laravel-tenants v3.0.0 requires illuminate/database ^6.0.0 -> satisfiable by illuminate/database[6.x-dev, v6.0.0, v6.0.1, v6.0.2, v6.0.3, v6.0.4, v6.1.0, v6.10.0, v6.11.0, v6.12.0, v6.13.0, v6.13.1, v6.14.0, v6.15.0, v6.15.1, v6.16.0, v6.17.0, v6.17.1, v6.18.0, v6.18.1, v6.18.2, v6.18.3, v6.18.4, v6.18.5, v6.18.6, v6.2.0, v6.3.0, v6.4.1, v6.5.0, v6.5.1, v6.5.2, v6.6.0, v6.6.1, v6.6.2, v6.7.0, v6.8.0].
- rinvex/laravel-tenants v3.0.1 requires illuminate/database ^6.0.0 -> satisfiable by illuminate/database[6.x-dev, v6.0.0, v6.0.1, v6.0.2, v6.0.3, v6.0.4, v6.1.0, v6.10.0, v6.11.0, v6.12.0, v6.13.0, v6.13.1, v6.14.0, v6.15.0, v6.15.1, v6.16.0, v6.17.0, v6.17.1, v6.18.0, v6.18.1, v6.18.2, v6.18.3, v6.18.4, v6.18.5, v6.18.6, v6.2.0, v6.3.0, v6.4.1, v6.5.0, v6.5.1, v6.5.2, v6.6.0, v6.6.1, v6.6.2, v6.7.0, v6.8.0].
- rinvex/laravel-tenants v3.0.2 requires illuminate/database ^6.0.0 -> satisfiable by illuminate/database[6.x-dev, v6.0.0, v6.0.1, v6.0.2, v6.0.3, v6.0.4, v6.1.0, v6.10.0, v6.11.0, v6.12.0, v6.13.0, v6.13.1, v6.14.0, v6.15.0, v6.15.1, v6.16.0, v6.17.0, v6.17.1, v6.18.0, v6.18.1, v6.18.2, v6.18.3, v6.18.4, v6.18.5, v6.18.6, v6.2.0, v6.3.0, v6.4.1, v6.5.0, v6.5.1, v6.5.2, v6.6.0, v6.6.1, v6.6.2, v6.7.0, v6.8.0].
- rinvex/laravel-tenants v3.0.3 requires illuminate/database ^6.0.0 -> satisfiable by illuminate/database[6.x-dev, v6.0.0, v6.0.1, v6.0.2, v6.0.3, v6.0.4, v6.1.0, v6.10.0, v6.11.0, v6.12.0, v6.13.0, v6.13.1, v6.14.0, v6.15.0, v6.15.1, v6.16.0, v6.17.0, v6.17.1, v6.18.0, v6.18.1, v6.18.2, v6.18.3, v6.18.4, v6.18.5, v6.18.6, v6.2.0, v6.3.0, v6.4.1, v6.5.0, v6.5.1, v6.5.2, v6.6.0, v6.6.1, v6.6.2, v6.7.0, v6.8.0].
- don't install illuminate/database 6.x-dev|don't install laravel/framework v7.0.0
- don't install illuminate/database v6.0.0|don't install laravel/framework v7.0.0
- don't install illuminate/database v6.0.1|don't install laravel/framework v7.0.0
- don't install illuminate/database v6.0.2|don't install laravel/framework v7.0.0
- don't install illuminate/database v6.0.3|don't install laravel/framework v7.0.0
- don't install illuminate/database v6.0.4|don't install laravel/framework v7.0.0
- don't install illuminate/database v6.1.0|don't install laravel/framework v7.0.0
- don't install illuminate/database v6.10.0|don't install laravel/framework v7.0.0
- don't install illuminate/database v6.11.0|don't install laravel/framework v7.0.0
- don't install illuminate/database v6.12.0|don't install laravel/framework v7.0.0
- don't install illuminate/database v6.13.0|don't install laravel/framework v7.0.0
- don't install illuminate/database v6.13.1|don't install laravel/framework v7.0.0
- don't install illuminate/database v6.14.0|don't install laravel/framework v7.0.0
- don't install illuminate/database v6.15.0|don't install laravel/framework v7.0.0
- don't install illuminate/database v6.15.1|don't install laravel/framework v7.0.0
- don't install illuminate/database v6.16.0|don't install laravel/framework v7.0.0
- don't install illuminate/database v6.17.0|don't install laravel/framework v7.0.0
- don't install illuminate/database v6.17.1|don't install laravel/framework v7.0.0
- don't install illuminate/database v6.18.0|don't install laravel/framework v7.0.0
- don't install illuminate/database v6.18.1|don't install laravel/framework v7.0.0
- don't install illuminate/database v6.18.2|don't install laravel/framework v7.0.0
- don't install illuminate/database v6.18.3|don't install laravel/framework v7.0.0
- don't install illuminate/database v6.18.4|don't install laravel/framework v7.0.0
- don't install illuminate/database v6.18.5|don't install laravel/framework v7.0.0
- don't install illuminate/database v6.18.6|don't install laravel/framework v7.0.0
- don't install illuminate/database v6.2.0|don't install laravel/framework v7.0.0
- don't install illuminate/database v6.3.0|don't install laravel/framework v7.0.0
- don't install illuminate/database v6.4.1|don't install laravel/framework v7.0.0
- don't install illuminate/database v6.5.0|don't install laravel/framework v7.0.0
- don't install illuminate/database v6.5.1|don't install laravel/framework v7.0.0
- don't install illuminate/database v6.5.2|don't install laravel/framework v7.0.0
- don't install illuminate/database v6.6.0|don't install laravel/framework v7.0.0
- don't install illuminate/database v6.6.1|don't install laravel/framework v7.0.0
- don't install illuminate/database v6.6.2|don't install laravel/framework v7.0.0
- don't install illuminate/database v6.7.0|don't install laravel/framework v7.0.0
- don't install illuminate/database v6.8.0|don't install laravel/framework v7.0.0
- Installation request for laravel/framework 7.0 -> satisfiable by laravel/framework[v7.0.0].
- Installation request for rinvex/laravel-tenants ^3.0 -> satisfiable by rinvex/laravel-tenants[v3.0.0, v3.0.1, v3.0.2, v3.0.3].

Installation failed, reverting ./composer.json to its original content.`

Dependabot can't resolve your PHP dependency files

Dependabot can't resolve your PHP dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Your requirements could not be resolved to an installable set of packages.
  Problem 1
    - felixkiss/uniquewith-validator 3.4.0 requires illuminate/support ^5.5|^6.0|^7.0 -> found illuminate/support[v5.5.0, ..., 5.8.x-dev, v6.0.0, ..., 6.x-dev, v7.0.0, ..., 7.x-dev] but it conflicts with your root composer.json require (^8.0.0 || ^9.0.0).
    - rinvex/laravel-support v5.0.0 requires felixkiss/uniquewith-validator ^3.4.0 -> satisfiable by felixkiss/uniquewith-validator[3.4.0].
    - Root composer.json requires rinvex/laravel-support ^5.0.0 -> satisfiable by rinvex/laravel-support[v5.0.0].

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

Is update after syncTenants missing or not?

I guess is on purpose not to update when doing syncTenants / attach / ... operations.

If so, it should be somehow expressed at docs for Laravel newbies:

$object->syncTenants($tenants)->update();
$object->attachTenants('tenant_slug')->update();

Would you be interested in a pull request on this?

Deprecated or not?

It's not the first package I see from Rinvex with this today:

image

But it is pointing to itself, so it's abandoned or not?

How to deal with querying code at console and seeders?

I've found that querying models on seeders are using using default root tenant so behaviour is unexpected.

$tenants = app('rinvex.tenants.tenant')->all();
foreach ($tenants as $tenant) {
     $all_users = User::withAllTenants($tenant)->get(); <-- Not working, gets main domain users
     $all_users = User::withAnyTenants($tenant)->get(); <-- Not working, gets main domain users
     $all_users = $tenant->entries(User::class)->get(); <-- Not working, gets main domain users
}

I finally made my own trait that works thanks to "withoutGlobalScopes":


trait ForTenant
{
    public function scopeForTenant($builder, $tenant)
    {
        return (new static())->newQuery()->withoutGlobalScopes(['tenantable'])->whereHas('tenants', function ($builder) use ($tenant) {
            $builder->where($key = $tenant->getKeyName(), $tenant->{$key})->where('is_active', true);
        });
    }
}

Could there be a better solution for this?

A)
withAnyTenantsWithoutGlobalScopes methods?

B)
initialize withAnyTenant methods with withoutGlobalScopes when application running outside request cycle?

C)
I still find strange I am the first to deal with this issue and there must be something wrong with my setup...

3 tenants with 3 subdomains created with a seeder:

  • domain.org
  • b.domain.org
  • c.domain.org

Config/app.php entry:

    'domains' => [
        env('MULTITENANT_DOMAIN', 'another.org') => [],
    ],

and at .env file:

MULTITENANT_DOMAIN=domain.org

Dependabot can't resolve your PHP dependency files

Dependabot can't resolve your PHP dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Your requirements could not be resolved to an installable set of packages.
  Problem 1
    - rinvex/laravel-support[v5.0.0, ..., v5.0.1] require felixkiss/uniquewith-validator ^3.4.0 -> satisfiable by felixkiss/uniquewith-validator[3.4.0].
    - rinvex/laravel-support v5.0.2 requires rinvex/tmp-felixkiss-uniquewith-validator 3.4.0 -> satisfiable by rinvex/tmp-felixkiss-uniquewith-validator[3.4.0].
    - felixkiss/uniquewith-validator 3.4.0 requires illuminate/support ^5.5|^6.0|^7.0 -> found illuminate/support[v5.5.0, ..., 5.8.x-dev, v6.0.0, ..., 6.x-dev, v7.0.0, ..., 7.x-dev] but it conflicts with your root composer.json require (^8.0.0 || ^9.0.0).
    - rinvex/tmp-felixkiss-uniquewith-validator 3.4.0 requires illuminate/support ^5.5|^6.0|^7.0 -> found illuminate/support[v5.5.0, ..., 5.8.x-dev, v6.0.0, ..., 6.x-dev, v7.0.0, ..., 7.x-dev] but it conflicts with your root composer.json require (^8.0.0 || ^9.0.0).
    - Root composer.json requires rinvex/laravel-support ^5.0.0 -> satisfiable by rinvex/laravel-support[v5.0.0, v5.0.1, v5.0.2].

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.