- Created Note model and controller for handling notes. - Added routes for notes CRUD operations. - Implemented notes index view with search and pinning functionality. - Created migration for notes table with necessary fields. - Developed event creation form with client and contract options.
65 lines
1.5 KiB
PHP
65 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Note;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\View\View;
|
|
|
|
class NoteController extends Controller
|
|
{
|
|
public function index(): View
|
|
{
|
|
$notes = Note::orderByDesc('is_pinned')
|
|
->orderByDesc('updated_at')
|
|
->get();
|
|
|
|
return view('notes.index', compact('notes'));
|
|
}
|
|
|
|
public function store(Request $request): JsonResponse
|
|
{
|
|
$data = $request->validate([
|
|
'title' => 'required|string|max:255',
|
|
'content' => 'nullable|array',
|
|
'color' => 'nullable|string|max:20',
|
|
'is_pinned' => 'boolean',
|
|
]);
|
|
|
|
$note = Note::create($data);
|
|
|
|
return response()->json($note, 201);
|
|
}
|
|
|
|
public function update(Request $request, Note $note): JsonResponse
|
|
{
|
|
$data = $request->validate([
|
|
'title' => 'required|string|max:255',
|
|
'content' => 'nullable|array',
|
|
'color' => 'nullable|string|max:20',
|
|
'is_pinned' => 'boolean',
|
|
]);
|
|
|
|
$note->update($data);
|
|
|
|
return response()->json($note);
|
|
}
|
|
|
|
public function destroy(Note $note): JsonResponse
|
|
{
|
|
$note->delete();
|
|
|
|
return response()->json(['ok' => true]);
|
|
}
|
|
|
|
public function togglePin(Note $note): JsonResponse
|
|
{
|
|
$note->update(['is_pinned' => ! $note->is_pinned]);
|
|
|
|
return response()->json($note);
|
|
}
|
|
}
|