changes
This commit is contained in:
@@ -21,7 +21,20 @@ class CreatePostTask
|
|||||||
public function run(array $data): Post
|
public function run(array $data): Post
|
||||||
{
|
{
|
||||||
$processedData = $this->postDataProcessor->processCreate($data);
|
$processedData = $this->postDataProcessor->processCreate($data);
|
||||||
return Post::create($processedData);
|
|
||||||
|
$tags = $processedData['tags'] ?? null;
|
||||||
|
|
||||||
|
// Удаляем теги из данных, так как они обрабатываются отдельно
|
||||||
|
unset($processedData['tags']);
|
||||||
|
|
||||||
|
$post = Post::create($processedData);
|
||||||
|
|
||||||
|
// Синхронизируем теги если они есть
|
||||||
|
if (!empty($tags) && is_array($tags)) {
|
||||||
|
$post->syncTags($tags);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $post;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -25,8 +25,17 @@ class UpdatePostTask
|
|||||||
...$data,
|
...$data,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$tags = $processedData['tags'] ?? null;
|
||||||
|
|
||||||
|
unset($processedData['tags']);
|
||||||
|
|
||||||
$post->update($processedData);
|
$post->update($processedData);
|
||||||
|
|
||||||
|
// Синхронизируем теги если они есть
|
||||||
|
if (!empty($tags) && is_array($tags)) {
|
||||||
|
$post->syncTags($tags);
|
||||||
|
}
|
||||||
|
|
||||||
return $post->fresh();
|
return $post->fresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,12 +67,13 @@ class PostController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function edit(Post $post): \Inertia\Response
|
public function edit(Post $post): \Inertia\Response
|
||||||
{
|
{
|
||||||
$post->load(['category', 'seo']);
|
$post->load(['category', 'seo', 'tags']);
|
||||||
$formData = $this->getPostFormDataAction->run();
|
$formData = $this->getPostFormDataAction->run();
|
||||||
|
|
||||||
return Inertia::render('Dashboard/Posts/Edit', [
|
return Inertia::render('Dashboard/Posts/Edit', [
|
||||||
'post' => [
|
'post' => [
|
||||||
...$post->toArray(),
|
...$post->toArray(),
|
||||||
|
'tags' => $post->tags->map(fn($tag) => ['id' => $tag->id, 'name' => $tag->name, 'slug' => $tag->slug]),
|
||||||
'status' => $post->status?->value ?? $post->status,
|
'status' => $post->status?->value ?? $post->status,
|
||||||
'publish_setting' => [
|
'publish_setting' => [
|
||||||
'publish_after' => $post->publish_at !== null,
|
'publish_after' => $post->publish_at !== null,
|
||||||
|
|||||||
Reference in New Issue
Block a user