fix: 🐛 set validation of unique i18n fields
This commit is contained in:
parent
f0311baaac
commit
9f6833aa81
3 changed files with 57 additions and 11 deletions
|
|
@ -30,7 +30,7 @@ class StoreSiteRequest extends FormRequest
|
|||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->merge([
|
||||
'project_manager_id' => is_array($this->project_manager_id)
|
||||
'project_manager_id' => is_array($this->project_manager_id) && count($this->project_manager_id)
|
||||
? intval($this->project_manager_id[0])
|
||||
: $this->project_manager_id,
|
||||
'gitlab_project_id' => is_array($this->gitlab_project_id)
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
|||
use Uwil\LaravelActivityLogs\Traits\HasActivityLog;
|
||||
use Uwil\LaravelBackend\Traits\Models\HasCache;
|
||||
use Uwil\LaravelBackend\Traits\Models\HasModelNaming;
|
||||
use Uwil\LaravelI18n\Helpers\TranslationHelper;
|
||||
use Uwil\LaravelI18n\Traits\Models\HasTranslations;
|
||||
|
||||
/**
|
||||
|
|
@ -46,6 +47,24 @@ class Brand extends Model
|
|||
'name',
|
||||
];
|
||||
|
||||
/**
|
||||
* Perform any actions required after the model boots.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
#[\Override]
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::creating(function (self $model): void {
|
||||
self::manageFields($model);
|
||||
});
|
||||
static::updating(function (self $model): void {
|
||||
self::manageFields($model);
|
||||
});
|
||||
}
|
||||
|
||||
// * METHODS.
|
||||
|
||||
/**
|
||||
* Get relations to include in the cache.
|
||||
*
|
||||
|
|
@ -56,7 +75,19 @@ class Brand extends Model
|
|||
return ['sites'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage model fields.
|
||||
*
|
||||
* @param self $model
|
||||
* @return void
|
||||
*/
|
||||
private static function manageFields(self $model): void
|
||||
{
|
||||
TranslationHelper::assertTranslationFieldIsUnique($model, $model->name, 'name');
|
||||
}
|
||||
|
||||
// * RELATIONS.
|
||||
|
||||
/**
|
||||
* Get sites associated to the brand.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ use Uwil\LaravelActivityLogs\Traits\HasActivityLog;
|
|||
use Uwil\LaravelBackend\Traits\Models\HasCache;
|
||||
use Uwil\LaravelBackend\Traits\Models\HasModelNaming;
|
||||
use Uwil\LaravelCommon\Helpers\ToolboxHelper;
|
||||
use Uwil\LaravelI18n\Helpers\TranslationHelper;
|
||||
use Uwil\LaravelI18n\Traits\Models\HasTranslations;
|
||||
|
||||
/**
|
||||
|
|
@ -62,17 +63,31 @@ class Site extends Model
|
|||
#[\Override]
|
||||
protected static function booted(): void
|
||||
{
|
||||
$assertUrls = function (self $model): void {
|
||||
if ($model->url_re7) {
|
||||
ToolboxHelper::assertNoInternalUrls('url_re7', $model->url_re7);
|
||||
}
|
||||
if ($model->url_prod) {
|
||||
ToolboxHelper::assertNoInternalUrls('url_prod', $model->url_prod);
|
||||
}
|
||||
};
|
||||
static::creating(function (self $model): void {
|
||||
self::manageFields($model);
|
||||
});
|
||||
static::updating(function (self $model): void {
|
||||
self::manageFields($model);
|
||||
});
|
||||
}
|
||||
|
||||
static::creating($assertUrls);
|
||||
static::updating($assertUrls);
|
||||
// * METHODS.
|
||||
|
||||
/**
|
||||
* Manage model fields.
|
||||
*
|
||||
* @param self $model
|
||||
* @return void
|
||||
*/
|
||||
private static function manageFields(self $model): void
|
||||
{
|
||||
TranslationHelper::assertTranslationFieldIsUnique($model, $model->name, 'name');
|
||||
if ($model->url_re7) {
|
||||
ToolboxHelper::assertNoInternalUrls('url_re7', $model->url_re7);
|
||||
}
|
||||
if ($model->url_prod) {
|
||||
ToolboxHelper::assertNoInternalUrls('url_prod', $model->url_prod);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue