-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAddDefaultPresentation.php
66 lines (57 loc) · 1.57 KB
/
AddDefaultPresentation.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
<?php
namespace App\Livewire\Schedule;
use App\Livewire\Forms\DefaultPresentationForm;
use App\Models\DefaultPresentation;
use App\Models\Room;
use App\Models\Timeslot;
use Illuminate\Foundation\Application;
use Illuminate\Http\RedirectResponse;
use Illuminate\Routing\Redirector;
use Illuminate\Support\Facades\Gate;
use Illuminate\View\View;
use Livewire\Component;
use LivewireUI\Modal\ModalComponent;
class AddDefaultPresentation extends ModalComponent
{
public $type;
public $rooms;
public DefaultPresentationForm $form;
/**
* Initializes the component
*
* @param $type
* @return void
*/
public function mount($type)
{
$this->type = $type;
$this->rooms = Room::all();
$this->form->setType($this->type);
}
/**
* Saves the data from the form
*
* @return \Illuminate\Contracts\Foundation\Application|Application|RedirectResponse|Redirector|void
*/
public function save()
{
$this->authorize('edit-schedule');
$this->form->save();
if ($this->form->isEntityCreated()) {
if (DefaultPresentation::opening() && DefaultPresentation::closing()) {
Timeslot::generateTimeslots();
}
return redirect(route('moderator.schedule.index'))
->with('status', ucfirst($this->type) . ' is successfully added.');
}
}
/**
* Renders the component
*
* @return View
*/
public function render(): View
{
return view('livewire.schedule.add-default-presentation');
}
}