HasNote.php 728 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace App\Http\Livewire\Traits;
  3. use App\Models\ReportProtocolloNote;
  4. trait HasNote{
  5. public $noteText;
  6. public $notes;
  7. public function addNote()
  8. {
  9. ReportProtocolloNote::create([
  10. 'report_id' => $this->dataId,
  11. 'text' => $this->noteText,
  12. 'created' => now(),
  13. 'created_by' => auth()->id() ?? 0,
  14. ]);
  15. $this->noteText = '';
  16. $this->refreshNotes();
  17. }
  18. public function removeNote($id)
  19. {
  20. ReportProtocolloNote::findOrFail($id)->delete();
  21. $this->refreshNotes();
  22. }
  23. private function refreshNotes()
  24. {
  25. $this->notes = ReportProtocolloNote::where('report_id', $this->dataId)->get();
  26. }
  27. }