Post.php 716 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Database\Eloquent\Factories\HasFactory;
  5. class Post extends Model
  6. {
  7. //
  8. use HasFactory;
  9. protected $fillable = [
  10. 'user_id',
  11. 'title',
  12. 'slug',
  13. 'content',
  14. 'is_published',
  15. 'published_at',
  16. 'scheduled_at',
  17. ];
  18. protected $casts = [
  19. 'published_at' => 'datetime',
  20. 'scheduled_at' => 'datetime',
  21. 'is_published' => 'boolean',
  22. ];
  23. public function comments()
  24. {
  25. return $this->hasMany(Comment::class);
  26. }
  27. public function scopePublished($query)
  28. {
  29. return $query->where('is_published', true);
  30. }
  31. }