Fix project edit and Site edit

This commit is contained in:
Jérémy Munsch 2021-10-22 12:27:48 +02:00
parent d21dce0fff
commit acb9bc9bbe
No known key found for this signature in database
GPG key ID: 55196BEE445F6049
2 changed files with 30 additions and 4 deletions

View file

@ -32,7 +32,18 @@ class Project extends Model
'validate' => [
'string',
'max:255',
'unique:sites,name'
// @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
function ($attribute, $value, $fail) {
$q = static::query();
if (request()->project) {
$q = $q->where('id', '!=', $this->id);
}
if ($q->where('name', $value)->exists()) {
$fail(__(':attribute est déjà utilisé', [
'attribute' => $attribute
]));
}
}
],
'required' => true,
'nullable' => false,

View file

@ -27,6 +27,10 @@ class Site extends Model
'description', 'todo'
];
protected $attributes = [
'status' => '',
];
public function __construct($attributes = [])
{
self::$editableProperties = [
@ -36,7 +40,18 @@ class Site extends Model
'validate' => [
'string',
'max:255',
'unique:sites,name'
// @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
function ($attribute, $value, $fail) {
$q = static::query();
if (request()->site) {
$q = $q->where('id', '!=', $this->id);
}
if ($q->where('name', $value)->exists()) {
$fail(__(':attribute est déjà utilisé', [
'attribute' => $attribute
]));
}
}
],
'required' => true,
'nullable' => false,
@ -54,8 +69,8 @@ class Site extends Model
'string',
'max:255'
],
'required' => true,
'nullable' => false,
'required' => false,
'nullable' => true, // n'est pas vraiment nullable en base
'actions' => [
CrudAction::view(),
CrudAction::create(),