validate([ 'type' => ['nullable', Rule::enum(TaxonomyType::class)], ]); $taxonomies = Taxonomy::query() ->when( isset($validated['type']), fn ($query) => $query->where('type', $validated['type']) ) ->get(); return response()->json([ 'success' => true, 'data' => [ 'taxonomies' => TaxonomyResource::collection($taxonomies), ], ]); } /** * Display the specified resource. */ public function show(Taxonomy $taxonomy): JsonResponse { return response()->json([ 'success' => true, 'data' => [ 'taxonomy' => new TaxonomyResource($taxonomy), ], ]); } }