-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAddNote.php
41 lines (34 loc) · 1.04 KB
/
AddNote.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
<?php
namespace App\Livewire;
use App\Models\AdditionalInfo;
use App\Models\User;
use App\Policies\NotePolicy;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Auth;
use Livewire\Component;
class AddNote extends Component
{
public User $attendee;
public ?string $note = null;
public function render(): Factory|View|Application
{
$this->note = $this->attendee->additionalInfo?->note;
return view('livewire.add-note')->with([
'note' => $this->note,
]);
}
public function updatedNote(string $note): void
{
$allowedToCreateNote = (new NotePolicy())->createNote(Auth::user())->allowed();
if ($allowedToCreateNote) {
$info = $this->attendee->additionalInfo;
if ($info == null) {
$info = new AdditionalInfo();
}
$info->note = $note;
$this->attendee->additionalInfo()->save($info);
}
}
}