Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stancl/tenancy how use #253

Open
dtemoment2015 opened this issue Feb 25, 2023 · 2 comments
Open

stancl/tenancy how use #253

dtemoment2015 opened this issue Feb 25, 2023 · 2 comments

Comments

@dtemoment2015
Copy link

Plz tell me how to connect with stancl/tenancy

@hanny-ph
Copy link

hanny-ph commented Feb 26, 2023

I think it's a bit difficult to seamlessly integrate with stancl/tenancy unless the author adds some changes, I could be wrong though.

I'd like to give you an idea of how to solve the issue, I'm sorry it's really ugly, but we can do nothing here. Please do the following steps:

  1. Create a new command.
  2. Copy the below code to your command class.
<?php

namespace App\Console\Commands;

use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Filesystem\Filesystem;
use Reliese\Coders\Model\Config;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Reliese\Coders\Model\Factory as ModelFactory;
use Reliese\Support\Classify;
use Stancl\Tenancy\Concerns\HasATenantsOption;
use Stancl\Tenancy\Concerns\TenantAwareCommand;

class GenerateTenantModels extends Command
{
    use TenantAwareCommand, HasATenantsOption;

    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'generate:tenant-models';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Generate Tenant Models';

    /**
     * Execute the console command.
     * @throws BindingResolutionException
     */
    public function handle()
    {
        $models = new ModelFactory(
            app()->make('db'),
            app()->make(Filesystem::class),
            new Classify(),
            new Config(app()->make('config')->get('models'))
        );
        $connection = DB::connection();

        $models->on($connection->getName())->map('public');
        $this->info("Check out your models for public");
    }
}
  1. Run php artisan generate:tenant-models --tenants=tenant_id_you_have

@Fludem
Copy link

Fludem commented Jan 4, 2024

@hanny-ph

I think you can just do

php artisan tenants:run code:models

IDE Helper Related: 1141

Tenancy For Laravel Docs: Tenant Commands

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants