validate($request, [ 'icon' => 'required|image', ]); $icon = $request->file('icon'); $path = $icon instanceof \Illuminate\Http\UploadedFile ? $icon->store('', 'icons') : false; return $path ? response()->json(['filename' => pathinfo($path)['basename']], 201) : response()->json(['message' => __('errors.file_upload_failed')], 500); } /** * Fetch a logo * * @param \Illuminate\Http\Request $request * @param \App\Services\LogoService $logoService * @return \Illuminate\Http\JsonResponse */ public function fetch(Request $request, LogoService $logoService) { $this->validate($request, [ 'service' => 'string|regex:/^[^:]+$/i', ]); $icon = $logoService->getIcon($request->service); return $icon ? response()->json(['filename' => $icon], 201) : response()->json(null, 204); } /** * delete an icon * * @param string $icon * @return \Illuminate\Http\JsonResponse */ public function delete(string $icon) { Storage::disk('icons')->delete($icon); return response()->json(null, 204); } }