The copy keeps the content, stack and team, but is unpublished, out of any review, and gets a title marked as a copy and a free slug. It replaces Filament's replicate action, which left the copy without a slug and still published. The same copy is available through the API. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
38 lines
975 B
PHP
38 lines
975 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\Api\V1;
|
|
|
|
use App\Http\Controllers\Api\V1\Concerns\ResolvesContent;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Support\ContentTypes;
|
|
use App\Support\Duplicator;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
/**
|
|
* A draft copy of a page, project, service or call — the panel's "Duplicate".
|
|
*/
|
|
class DuplicateController extends Controller
|
|
{
|
|
use ResolvesContent;
|
|
|
|
public function store(Request $request): JsonResponse
|
|
{
|
|
$record = $this->record($request);
|
|
|
|
$this->authorize('view', $record);
|
|
$this->authorize('create', $record::class);
|
|
|
|
$copy = Duplicator::duplicate($record);
|
|
|
|
return response()->json(['data' => [
|
|
'type' => $this->content($request),
|
|
'id' => $copy->getKey(),
|
|
'title' => ContentTypes::title($copy),
|
|
'slug' => (object) $copy->getTranslations('slug'),
|
|
]], 201);
|
|
}
|
|
}
|