fix: Fix default Salon directory

This commit is contained in:
Vincent BRIDIER 2025-06-12 15:47:56 +02:00
parent d4c72ed804
commit 728568d812
No known key found for this signature in database
GPG key ID: 8571BFA20420D512
3 changed files with 26 additions and 13 deletions

View file

@ -146,6 +146,30 @@ class Directory extends Model
return Directory::renderDirectories($directoriesFiltered);
}
/**
* Set default settings for a specific tenant.
*
* @param \App\Models\Tenant $tenant
* @return void
*/
public function setDefaultDirectories(Tenant $tenant): void
{
// Default locked salon directory.
$directory = new self();
$directory->name = [
"fr" => "Salon",
"en" => "Salon",
"de" => "Wohnzimmer",
"nl" => "Tentoonstelling",
];
$directory->directory_id = null;
$directory->needAuthorization = 0;
$directory->is_system = 1;
$directory->order = 1;
$directory->tenant_id = $tenant->getKey();
$directory->saveOrFail();
}
// * RELATIONSHIPS
/**

View file

@ -48,6 +48,7 @@ class Tenant extends BaseTenant implements TenantContract
static::created(function (self $model) {
(new Setting())->setDefaultSettings($model);
(new Formulary())->setDefaultFormularies($model);
(new Directory())->setDefaultDirectories($model);
self::resetCache();
});
static::updating(function (self $model) {

View file

@ -17,19 +17,7 @@ class DirectorySeeder extends Seeder
*/
public function run(): void
{
$directory = new Directory();
$directory->name = [
"fr" => "Salon",
"en" => "Salon",
"de" => "Wohnzimmer",
"nl" => "Tentoonstelling",
];
$directory->directory_id = null;
$directory->needAuthorization = 0;
$directory->is_system = 1;
$directory->order = 1;
$directory->tenant_id = Tenant::query()->first()->getKey();
$directory->saveOrFail();
// Default "Salon" directory is created in the Tenant model.
Directory::factory(14)->create();