Added validation rules for duty hours
This commit is contained in:
parent
d49bb5eaa7
commit
8678ce520b
2 changed files with 25 additions and 1 deletions
|
|
@ -63,6 +63,22 @@ class Dutyhour extends Model
|
|||
'date' => [
|
||||
'label' => trans('Date'),
|
||||
'type' => CrudType::date(),
|
||||
'validate' => [
|
||||
'date',
|
||||
'after_or_equal:today',
|
||||
// @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
||||
function ($attribute, $value, $fail) {
|
||||
$q = static::query();
|
||||
if (request()->dutyhour) {
|
||||
$q = $q->where('id', '!=', $this->id);
|
||||
}
|
||||
if ($q->where('date', $value)->exists()) {
|
||||
$fail(__('La :attribute est déjà utilisée', [
|
||||
'attribute' => $attribute
|
||||
]));
|
||||
}
|
||||
}
|
||||
],
|
||||
'nullable' => false,
|
||||
'actions' => [
|
||||
CrudAction::viewAny(),
|
||||
|
|
@ -74,6 +90,10 @@ class Dutyhour extends Model
|
|||
'person' => [
|
||||
'label' => trans('Personne présente'),
|
||||
'type' => CrudType::string(),
|
||||
'validate' => [
|
||||
'string',
|
||||
'max:255'
|
||||
],
|
||||
'nullable' => false,
|
||||
'actions' => [
|
||||
CrudAction::viewAny(),
|
||||
|
|
@ -85,6 +105,10 @@ class Dutyhour extends Model
|
|||
'place' => [
|
||||
'label' => trans('Lieu'),
|
||||
'type' => CrudType::string(),
|
||||
'validate' => [
|
||||
'string',
|
||||
'max:255'
|
||||
],
|
||||
'nullable' => false,
|
||||
'actions' => [
|
||||
CrudAction::viewAny(),
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ class CreateDutyhoursTable extends Migration
|
|||
{
|
||||
Schema::create('dutyhours', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->date('date');
|
||||
$table->date('date')->unique();
|
||||
$table->string('person');
|
||||
$table->string('place');
|
||||
$table->timestamps();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue