reliese / laravel

Reliese Laravel Model Generator
MIT License
1.49k stars 316 forks source link

stancl/tenancy how use #253

Open dtemoment2015 opened 1 year ago

dtemoment2015 commented 1 year ago

Plz tell me how to connect with stancl/tenancy

hanny-ph commented 1 year ago

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 commented 10 months ago

@hanny-ph

I think you can just do

php artisan tenants:run code:models

IDE Helper Related: 1141

Tenancy For Laravel Docs: Tenant Commands