cms/app/Services/PostService.php
Funky Waddle 37ed997989 feat(cms): initialize Laravel project structure and core CMS files
- Added standard Laravel directory structure and configuration.

- Included Svelte and Tailwind configuration for the admin interface.

- Added core PHPUnit and testing scripts.
2026-04-13 12:48:06 -05:00

58 lines
1.2 KiB
PHP

<?php
namespace App\Services;
use App\Models\CustomPostType;
use App\Models\Post;
use Illuminate\Support\Facades\Auth;
class PostService
{
/**
* Store a newly created post.
*
* @param CustomPostType $customPostType
* @param array $data
* @return Post
*/
public function storePost(CustomPostType $customPostType, array $data): Post
{
$data['custom_post_type_id'] = $customPostType->id;
$data['user_id'] = Auth::id();
if ($data['status'] === 'published' && empty($data['published_at'])) {
$data['published_at'] = now();
}
return Post::create($data);
}
/**
* Update the specified post.
*
* @param Post $post
* @param array $data
* @return Post
*/
public function updatePost(Post $post, array $data): Post
{
if ($data['status'] === 'published' && !$post->published_at && !$data['published_at']) {
$data['published_at'] = now();
}
$post->update($data);
return $post;
}
/**
* Remove the specified post.
*
* @param Post $post
* @return bool
*/
public function deletePost(Post $post): bool
{
return (bool) $post->delete();
}
}