getFirstMedia('receipts'); if ($media) { $imagePath = $media->getPath(); } else { return response()->json([ 'error' => 'receipt_does_not_exist', ]); } } $type = \File::mimeType($imagePath); $image = 'data:'.$type.';base64,'.base64_encode(file_get_contents($imagePath)); return response()->json([ 'image' => $image, 'type' => $type, ]); } }