Allow artworks to have one primary category and extra secondaries.
Keep artwork_category as membership, store a deterministic primary_category_id, and let upload plus studio pick up to five additional same-type categories without changing canonical URLs.
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Artworks\ArtworkCreateRequest;
|
||||
use App\Http\Resources\ArtworkListResource;
|
||||
use App\Http\Resources\ArtworkResource;
|
||||
use App\Services\ArtworkService;
|
||||
use App\Services\Artworks\ArtworkDraftService;
|
||||
use App\Models\Category;
|
||||
use App\Services\Artworks\ArtworkDraftService;
|
||||
use App\Services\ArtworkService;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
@@ -29,9 +30,12 @@ class ArtworkController extends Controller
|
||||
$user = $request->user();
|
||||
$data = $request->validated();
|
||||
|
||||
$categoryId = isset($data['category']) && ctype_digit((string) $data['category'])
|
||||
? (int) $data['category']
|
||||
: null;
|
||||
$categoryId = isset($data['primary_category_id']) && ctype_digit((string) $data['primary_category_id'])
|
||||
? (int) $data['primary_category_id']
|
||||
: (isset($data['category']) && ctype_digit((string) $data['category'])
|
||||
? (int) $data['category']
|
||||
: null);
|
||||
$secondaryCategoryIds = array_values(array_map('intval', $data['secondary_category_ids'] ?? []));
|
||||
|
||||
$result = $drafts->createDraft(
|
||||
$user,
|
||||
@@ -40,6 +44,7 @@ class ArtworkController extends Controller
|
||||
$categoryId,
|
||||
(bool) ($data['is_mature'] ?? false),
|
||||
$data['group'] ?? null,
|
||||
$secondaryCategoryIds,
|
||||
);
|
||||
|
||||
return response()->json([
|
||||
|
||||
Reference in New Issue
Block a user