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:
test
2026-09-20 14:50:12 +02:00
parent 4d60a876af
commit 232880e01f
43 changed files with 2896 additions and 565 deletions
@@ -17,12 +17,16 @@ final class ArtworkDraftService
{
public function __construct(
private readonly GroupService $groups,
private readonly ArtworkCategoryService $categories,
) {
}
public function createDraft(User $user, string $title, ?string $description, ?int $categoryId = null, bool $isMature = false, string|int|null $groupIdentifier = null): ArtworkDraftResult
/**
* @param list<int> $secondaryCategoryIds
*/
public function createDraft(User $user, string $title, ?string $description, ?int $categoryId = null, bool $isMature = false, string|int|null $groupIdentifier = null, array $secondaryCategoryIds = []): ArtworkDraftResult
{
return DB::transaction(function () use ($user, $title, $description, $categoryId, $isMature, $groupIdentifier) {
return DB::transaction(function () use ($user, $title, $description, $categoryId, $isMature, $groupIdentifier, $secondaryCategoryIds) {
$slug = $this->makeSlug($title);
$group = $this->resolveGroup($user, $groupIdentifier);
@@ -50,9 +54,8 @@ final class ArtworkDraftService
'artwork_status' => 'draft',
]);
// Attach the selected category to the artwork pivot table
if ($categoryId !== null && \App\Models\Category::where('id', $categoryId)->exists()) {
$artwork->categories()->sync([$categoryId]);
if ($categoryId !== null || $secondaryCategoryIds !== []) {
$this->categories->sync($artwork, $categoryId, $secondaryCategoryIds, 'user', false);
}
if ($group) {