-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAddKeynoteModal.php
74 lines (63 loc) · 1.72 KB
/
AddKeynoteModal.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
70
71
72
73
74
<?php
namespace App\Livewire\Edition;
use App\Livewire\Forms\KeynoteForm;
use App\Models\Edition;
use Illuminate\Support\Facades\Auth;
use Illuminate\View\View;
use Livewire\WithFileUploads;
use LivewireUI\Modal\ModalComponent;
class AddKeynoteModal extends ModalComponent
{
use WithFileUploads;
public Edition $edition;
public KeynoteForm $form;
/**
* Initializes the component
*
* @param Edition $edition
* @return void
*/
public function mount(Edition $edition): void
{
$this->edition = $edition;
$this->form->setKeynote($edition);
}
/**
* Saves the updates made on the form
*/
public function save()
{
if (Auth::user()->cannot('update', Edition::class)) {
abort(403);
}
if ($this->edition->keynote_photo_path && $this->edition->keynote_photo_path == $this->form->keynote_photo_path) {
$this->validate([
'form.keynote_name' => ['required', 'string', 'min:3', 'max:255'],
'form.keynote_description' => ['required', 'string', 'min:3', 'max:700'],
]);
} else {
$this->validate();
}
$this->form->update();
return redirect(route('moderator.editions.show', $this->edition))
->with('status', 'Keynote speaker successfully updated.');
}
/**
* Sets the maximum width of the modal according to docs
*
* @return string
*/
public static function modalMaxWidth(): string
{
return 'xl';
}
/**
* Renders the component
*
* @return View
*/
public function render() : View
{
return view('livewire.edition.add-keynote-modal');
}
}