Comment.php 693 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Database\Eloquent\SoftDeletes;
  5. class Comment extends Model
  6. {
  7. use SoftDeletes;
  8. const STATUS_PENDING = 0;
  9. const STATUS_PUBLISHED = 1;
  10. const STATUS_REJECTED = 2;
  11. // Наличие fillable требуется только при использовании mass assignment, т.е. создание записи из ассоциативного массива
  12. protected $fillable = [
  13. "name",
  14. "email",
  15. "content",
  16. "status"
  17. ];
  18. function scopePublished($query) {
  19. $query->where("status", static::STATUS_PUBLISHED);
  20. }
  21. function scopeRecent($query) {
  22. $query->orderBy("created_at", "desc");
  23. }
  24. }