-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathEditionForm.php
69 lines (55 loc) · 1.91 KB
/
EditionForm.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
64
65
66
67
68
69
<?php
namespace App\Livewire\Forms;
use App\Models\Edition;
use Carbon\Carbon;
use Livewire\Attributes\Validate;
use Livewire\Form;
class EditionForm extends Form
{
public $edition;
public $upperBoundary;
public $lowerBoundary;
#[Validate('required')]
public $name;
#[Validate(['required', 'date', 'after:lowerBoundary', 'before:upperBoundary'])]
public $start_at;
#[Validate(['required', 'date', 'after:start_at', 'before:upperBoundary'])]
public $end_at;
#[Validate(['required', 'numeric', 'min:1', 'max:120'])]
public $lecture_duration;
#[Validate('required', 'numeric', 'min:1', 'max:180')]
public $workshop_duration;
protected $messages = [
'start_at.after' => 'The start date should be at least a month from now.',
'start_at.before' => 'The start date should be two years from now at latest.',
'end_at.after' => 'The end date should be later than start date.',
'end_at.before' => 'The end date should be two years from now at latest.',
];
/**
* Sets the edition details per each field
* @param Edition $edition
* @return void
*/
public function setEdition(Edition $edition)
{
$this->edition = $edition;
$this->name = $edition->name;
$this->start_at = $edition->start_at->format('Y-m-d\TH:i:s');
$this->end_at = $edition->end_at->format('Y-m-d\TH:i:s');
$this->lecture_duration = $edition->lecture_duration;
$this->workshop_duration = $edition->workshop_duration;
$this->upperBoundary = Carbon::now()->addYears(2);
$this->lowerBoundary = Carbon::now()->addMonth();
}
/**
* Updates the edition details with the new data
* Updates start/end date of the event that is responsible for the new state
* @return void
*/
public function update()
{
$this->edition->update(
$this->all()
);
}
}