| 1234567891011121314151617181920212223242526272829303132333435363738 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- class Post extends Model
- {
- //
- use HasFactory;
- protected $fillable = [
- 'user_id',
- 'title',
- 'slug',
- 'content',
- 'is_published',
- 'published_at',
- 'scheduled_at',
- ];
- protected $casts = [
- 'published_at' => 'datetime',
- 'scheduled_at' => 'datetime',
- 'is_published' => 'boolean',
- ];
- public function comments()
- {
- return $this->hasMany(Comment::class);
- }
- public function scopePublished($query)
- {
- return $query->where('is_published', true);
- }
- }
|