Add (posts)

This commit is contained in:
2023-07-27 02:18:38 +08:00
parent 1c917b865d
commit e70195f4f7
15 changed files with 525 additions and 34 deletions

50
app/Models/Author.php Normal file
View File

@@ -0,0 +1,50 @@
<?php
/**
* Created by Reliese Model.
*/
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
/**
* Class Author
*
* @property int $id
* @property string $name
* @property string $avatar
* @property string $bio
* @property bool $enabled
* @property bool $public
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
*
* @property Collection|Post[] $posts
*
* @package App\Models
*/
class Author extends Model
{
protected $table = 'authors';
protected $casts = [
'enabled' => 'bool',
'public' => 'bool'
];
protected $fillable = [
'name',
'avatar',
'bio',
'enabled',
'public'
];
public function posts()
{
return $this->hasMany(Post::class);
}
}

11
app/Models/DraftPost.php Normal file
View File

@@ -0,0 +1,11 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class DraftPost extends Model
{
use HasFactory;
}

70
app/Models/Post.php Normal file
View File

@@ -0,0 +1,70 @@
<?php
/**
* Created by Reliese Model.
*/
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
/**
* Class Post
*
* @property int $id
* @property string|null $title
* @property string|null $slug
* @property string|null $excerpt
* @property int|null $author_id
* @property string $featured_image
* @property string $editor
* @property array|null $body
* @property string $post_format
* @property int $comment_count
* @property int $likes_count
* @property string $status
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
*
* @property Author|null $author
* @property Collection|PostCategory[] $post_categories
*
* @package App\Models
*/
class Post extends Model
{
protected $table = 'posts';
protected $casts = [
'author_id' => 'int',
'body' => 'json',
'comment_count' => 'int',
'likes_count' => 'int'
];
protected $fillable = [
'title',
'slug',
'excerpt',
'author_id',
'featured_image',
'editor',
'body',
'post_format',
'comment_count',
'likes_count',
'status'
];
public function author()
{
return $this->belongsTo(Author::class);
}
public function post_categories()
{
return $this->hasMany(PostCategory::class);
}
}

View File

@@ -0,0 +1,49 @@
<?php
/**
* Created by Reliese Model.
*/
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
/**
* Class PostCategory
*
* @property int $id
* @property int $post_id
* @property int $category_id
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
*
* @property Category $category
* @property Post $post
*
* @package App\Models
*/
class PostCategory extends Model
{
protected $table = 'post_categories';
protected $casts = [
'post_id' => 'int',
'category_id' => 'int'
];
protected $fillable = [
'post_id',
'category_id'
];
public function category()
{
return $this->belongsTo(Category::class);
}
public function post()
{
return $this->belongsTo(Post::class);
}
}