Comment.php 897 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Factories\HasFactory;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Database\Eloquent\SoftDeletes;
  6. class Comment extends Model
  7. {
  8. use HasFactory, SoftDeletes;
  9. protected $fillable = [
  10. 'submission_id',
  11. 'author',
  12. 'content',
  13. ];
  14. protected $casts = [
  15. 'created_at' => 'datetime',
  16. 'updated_at' => 'datetime',
  17. 'deleted_at' => 'datetime',
  18. ];
  19. // Связь многие-к-одному: комментарий принадлежит заявке
  20. public function submission()
  21. {
  22. return $this->belongsTo(Submission::class);
  23. }
  24. // Полиморфная связь: комментарий может иметь вложения
  25. public function attachments()
  26. {
  27. return $this->morphMany(Attachment::class, 'attachable');
  28. }
  29. }