Article.php 542 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Database\Eloquent\SoftDeletes;
  5. class Article extends Model
  6. {
  7. use SoftDeletes;
  8. const STATUS_DRAFT = 0;
  9. const STATUS_PENDING = 1;
  10. const STATUS_PUBLISHED = 2;
  11. const STATUS_ARCHIVE = 3;
  12. function scopePending($query) {
  13. $query->where("status", static::STATUS_PENDING);
  14. }
  15. function scopePublished($query) {
  16. $query->where("status", static::STATUS_PUBLISHED);
  17. }
  18. function comments() {
  19. return $this->morphMany(Comment::class, "commentable");
  20. }
  21. }