validate([ 'file' => 'required|file|mimes:jpg,png,pdf|max:5120', 'pbg_type' => 'string' ]); $file = $request->file('file'); $path = $file->store("uploads/pbg-tasks/{$pbg_task_id}", "public"); $attachment = PbgTaskAttachment::create([ 'pbg_task_id' => $pbg_task_id, 'file_name' => $file->getClientOriginalName(), 'file_path' => $path, 'pbg_type' => $request->pbg_type ]); return response()->json([ 'message' => 'File uploaded successfully.', 'attachment' => [ 'id' => $attachment->id, 'file_name' => $attachment->file_name, 'file_url' => Storage::url($attachment->file_path), 'pbg_type' => $attachment->pbg_type ] ]); }catch(\Exception $e){ \Log::error($e->getMessage()); return response()->json([ "success" => false, "message" => $e->getTraceAsString() ]); } } /** * Display the specified resource. */ public function show(string $id) { // } /** * Update the specified resource in storage. */ public function update(Request $request, string $id) { // } /** * Remove the specified resource from storage. */ public function destroy(string $id) { // } }