Review.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  7. use Illuminate\Database\Eloquent\Relations\BelongsToMany;
  8. use Illuminate\Database\Eloquent\Relations\HasMany;
  9. class Review extends Model
  10. {
  11. use HasFactory, SoftDeletes;
  12. protected $fillable = [
  13. 'schedule_id',
  14. 'origin',
  15. 'origin_id',
  16. 'stars',
  17. 'comment',
  18. ];
  19. protected $casts = [
  20. 'stars' => 'decimal:1',
  21. 'created_at' => 'datetime',
  22. 'updated_at' => 'datetime',
  23. 'deleted_at' => 'datetime',
  24. ];
  25. public function schedule(): BelongsTo
  26. {
  27. return $this->belongsTo(Schedule::class);
  28. }
  29. public function originProvider(): BelongsTo
  30. {
  31. return $this->belongsTo(Provider::class, 'origin_id');
  32. }
  33. public function originClient(): BelongsTo
  34. {
  35. return $this->belongsTo(Client::class, 'origin_id');
  36. }
  37. public function reviewsImprovements(): HasMany
  38. {
  39. return $this->hasMany(ReviewImprovement::class);
  40. }
  41. public function improvements(): BelongsToMany
  42. {
  43. return $this->belongsToMany(
  44. ImprovementType::class,
  45. 'reviews_improvements',
  46. 'review_id',
  47. 'improvement_type_id'
  48. )->withTimestamps();
  49. }
  50. }