- Restructure field editor dialog: move Options section to bottom with divider and subheader, fix delete button with flex layout - Change tag_category (single string) to tag_categories (JSON array) supporting multiple category selection in tag picker fields - Portal tag picker now groups tags by category with subheaders - Add generic file upload endpoint (FileUploadService + UploadController) - Replace email branding logo URL text field with ImageUploadField - Update Partner crowd type default icon to tabler-affiliate - Apply changes consistently to both field and template dialogs Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
53 lines
1.5 KiB
PHP
53 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\Api\V1;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Services\FileUploadService;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
final class UploadController extends Controller
|
|
{
|
|
public function __construct(
|
|
private readonly FileUploadService $uploadService,
|
|
) {}
|
|
|
|
public function uploadImage(Request $request): JsonResponse
|
|
{
|
|
$request->validate([
|
|
'file' => ['required', 'file', 'max:5120'],
|
|
'purpose' => ['required', 'string', 'in:logo,banner,icon,avatar'],
|
|
]);
|
|
|
|
$user = $request->user();
|
|
$organisation = $user->organisations()->first();
|
|
|
|
try {
|
|
$url = $this->uploadService->uploadImage(
|
|
file: $request->file('file'),
|
|
directory: 'uploads/' . $request->input('purpose'),
|
|
organisationId: $organisation?->id,
|
|
);
|
|
} catch (\DomainException $e) {
|
|
return response()->json(['message' => $e->getMessage()], 422);
|
|
}
|
|
|
|
activity('upload')
|
|
->causedBy($user)
|
|
->withProperties([
|
|
'purpose' => $request->input('purpose'),
|
|
'original_name' => $request->file('file')->getClientOriginalName(),
|
|
'size_bytes' => $request->file('file')->getSize(),
|
|
'mime' => $request->file('file')->getMimeType(),
|
|
])
|
|
->log('image.uploaded');
|
|
|
|
return response()->json([
|
|
'data' => ['url' => $url],
|
|
]);
|
|
}
|
|
}
|