ForestAdmin / laravel-forestadmin

🌱 Laravel Agent for Forest Admin
GNU General Public License v3.0
73 stars 16 forks source link

Can't ignore models #55

Closed storm23 closed 2 years ago

storm23 commented 2 years ago

Expected behavior

I would like to ignore some models during ForestAdmin mapping.

Actual behavior

I can specify only one dir and/or namespace for models mapping.

Failure Logs

  InvalidArgumentException 

  Database connection [merchant] not configured.

  at vendor/laravel/framework/src/Illuminate/Database/DatabaseManager.php:161
    157▕         // If the configuration doesn't exist, we'll throw an exception and bail.
    158▕         $connections = $this->app['config']['database.connections'];
    159▕ 
    160▕         if (is_null($config = Arr::get($connections, $name))) {
  ➜ 161▕             throw new InvalidArgumentException("Database connection [{$name}] not configured.");
    162▕         }
    163▕ 
    164▕         return (new ConfigurationUrlParser)
    165▕                     ->parseConfiguration($config);

      +13 vendor frames 
  14  artisan:37
      Illuminate\Foundation\Console\Kernel::handle()

Context

In my application I have one main database plus one database per clients (= merchants) : it's a multi-tenancy architecture. In order to that, in merchant database models I specify the DB connection like this :

protected $connection = 'merchant';

"merchant" is the connection name of a DB connection set on the fly, depending of the context.

I simply would like to ignore these models.

For example like that :

/* /config/forest.php */
<?php

return [
    'models_directory'      => env('MODEL_DIRECTORY', 'app/Models/'),
    'models_namespace'      => env('MODEL_NAMESPACE', 'App\Models\\'),
    'models_ignore'         => [
        '\MyNamespace\Models\Merchant',
        '\MyNamespace\Models\Other',
    ],
    'json_file_path'        => env('JSON_FILE_PATH', '.forestadmin-schema.json'),
    'send_apimap_automatic' => env('FOREST_SEND_APIMAP_AUTOMATIC', false),
    'api'                   => [
        'url'         => env('FOREST_URL', 'https://api.forestadmin.com'),
        'secret'      => env('FOREST_ENV_SECRET'),
        'auth-secret' => env('FOREST_AUTH_SECRET'),
    ],
];
storm23 commented 2 years ago

I've take a look to the feat/multi-directories-models : it can resolve this issue.

storm23 commented 2 years ago

It's resolved by :