middleware('auth:sanctum')->only(['store', 'update', 'destroy']); } /** * Seznam záznamů country-WWL (stránkovaně). */ public function index(Request $request): JsonResponse { $perPage = (int) $request->get('per_page', 100); $items = CountryWwl::query() ->orderBy('country_name') ->orderBy('wwl') ->paginate($perPage); return response()->json($items); } /** * Vytvoření nového country-WWL záznamu. * Autorizace přes CountryWwlPolicy@create. */ public function store(Request $request): JsonResponse { $this->authorize('create', CountryWwl::class); $data = $this->validateData($request); $item = CountryWwl::create($data); return response()->json($item, 201); } /** * Detail jednoho country-WWL záznamu. */ public function show(CountryWwl $country_wwl): JsonResponse { return response()->json($country_wwl); } /** * Aktualizace existujícího country-WWL záznamu (partial update). * Autorizace přes CountryWwlPolicy@update. */ public function update(Request $request, CountryWwl $country_wwl): JsonResponse { $this->authorize('update', $country_wwl); $data = $this->validateData($request, partial: true); $country_wwl->fill($data); $country_wwl->save(); return response()->json($country_wwl); } /** * Smazání country-WWL záznamu. * Autorizace přes CountryWwlPolicy@delete. */ public function destroy(CountryWwl $country_wwl): JsonResponse { $this->authorize('delete', $country_wwl); $country_wwl->delete(); return response()->json(null, 204); } /** * Validace dat pro store / update. */ protected function validateData(Request $request, bool $partial = false): array { $required = $partial ? 'sometimes' : 'required'; return $request->validate([ 'country_name' => [$required, 'string', 'max:150'], 'wwl' => [$required, 'string', 'size:4'], ]); } }