-
Notifications
You must be signed in to change notification settings - Fork 2
/
EditionEventForm.php
63 lines (51 loc) · 1.73 KB
/
EditionEventForm.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
namespace App\Livewire\Forms;
use App\Models\Edition;
use App\Models\EditionEvent;
use Carbon\Carbon;
use Livewire\Attributes\Validate;
use Livewire\Form;
class EditionEventForm extends Form
{
public $edition;
public $editionEvent;
public $upperBoundary;
public $lowerBoundary;
#[Validate(['required', 'date', 'after_or_equal:today', 'before:upperBoundary'])]
public $start_at;
#[Validate(['required', 'date', 'after:start_at', 'before:upperBoundary'])]
public $end_at;
protected $messages = [
'start_at.after' => 'The start date should be at least from today.',
'start_at.before' => 'The start date should be earlier than the start date of edition.',
'end_at.after' => 'The end date should be later than start date.',
'end_at.before' => 'The end date should be be earlier than the start date of edition.',
];
/**
* Sets the event details per each field
*
* @param EditionEvent $editionEvent
* @param Edition $edition
* @return void
*/
public function setEditionEvent(EditionEvent $editionEvent, Edition $edition): void
{
$this->edition = $edition;
$this->editionEvent = $editionEvent;
$this->start_at = $editionEvent->start_at ? $editionEvent->start_at->format('Y-m-d') : '';
$this->end_at = $editionEvent->end_at ? $editionEvent->end_at->format('Y-m-d') : '';
$this->upperBoundary = $this->edition->start_at;
$this->lowerBoundary = Carbon::now()->subMonths(2);
}
/**
* Updates the edition details with the new data
*
* @return void
*/
public function update(): void
{
$this->editionEvent->update(
$this->all()
);
}
}