- add notes
This commit is contained in:
		
							
								
								
									
										84
									
								
								app/Http/Controllers/Dashboard/NoteController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										84
									
								
								app/Http/Controllers/Dashboard/NoteController.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,84 @@ | ||||
| <?php | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace App\Http\Controllers\Dashboard; | ||||
|  | ||||
| use App\Http\Controllers\Controller; | ||||
| use App\Http\Requests\NoteRequest; | ||||
| use App\Http\Resources\NoteCollection; | ||||
| use App\Http\Resources\NoteResource; | ||||
| use App\Models\Note; | ||||
| use Illuminate\Http\RedirectResponse; | ||||
| use Inertia\Response as InertiaResponse; | ||||
|  | ||||
| class NoteController extends Controller | ||||
| { | ||||
|     public function index():  InertiaResponse | ||||
|     { | ||||
|         return inertia( | ||||
|             'Notes/Index', | ||||
|             [ | ||||
|                 'notes' => new NoteCollection( | ||||
|                         Note::query() | ||||
|                             ->orderByDesc('id') | ||||
|                             ->get() | ||||
|                     ), | ||||
|             ] | ||||
|         ); | ||||
|     } | ||||
|  | ||||
|     public function create(): InertiaResponse | ||||
|     { | ||||
|         return inertia('Notes/Create'); | ||||
|     } | ||||
|  | ||||
|     public function store(NoteRequest $request): RedirectResponse | ||||
|     { | ||||
|         $note = Note::query()->create([ | ||||
|             'title' => $request->get('title'), | ||||
|             'note' => $request->get('note'), | ||||
|         ]); | ||||
|  | ||||
|         return redirect() | ||||
|             ->route('admin.note.show', compact('note')) | ||||
|             ->with('success', 'Utworzono nową notatkę.'); | ||||
|     } | ||||
|  | ||||
|     public function show(Note $note): InertiaResponse | ||||
|     { | ||||
|         return inertia('Notes/Show', ['note' => new NoteResource($note)]); | ||||
|     } | ||||
|  | ||||
|     public function edit(Note $note): InertiaResponse | ||||
|     { | ||||
|         return inertia('Notes/Edit', ['note' => new NoteResource($note)]); | ||||
|     } | ||||
|  | ||||
|     public function update(NoteRequest $request, Note $note): RedirectResponse | ||||
|     { | ||||
|         $note->update([ | ||||
|             'title' => $request->get('title'), | ||||
|             'note' => $request->get('note'), | ||||
|         ]); | ||||
|  | ||||
|         return redirect() | ||||
|             ->route('admin.note.show', compact('note')) | ||||
|             ->with('success', 'Notatka ' . $request->get('title') . ' została zaktualizowana.'); | ||||
|     } | ||||
|  | ||||
|     public function delete(Note $note): InertiaResponse | ||||
|     { | ||||
|         return inertia('Notes/ConfirmDelete', ['note' => new NoteResource($note)]); | ||||
|     } | ||||
|  | ||||
|     public function destroy(Note $note): RedirectResponse | ||||
|     { | ||||
|         $title = $note->title; | ||||
|         $note->delete(); | ||||
|  | ||||
|         return redirect() | ||||
|             ->route('admin.note.index') | ||||
|             ->with('info', 'Notatka ' . $title . ' została usunięta.'); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user