Review.php 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. /**
  10. * @property int $id
  11. * @property int $schedule_id
  12. * @property string $origin
  13. * @property int $origin_id
  14. * @property numeric $stars
  15. * @property string|null $comment
  16. * @property \Illuminate\Support\Carbon|null $created_at
  17. * @property \Illuminate\Support\Carbon|null $updated_at
  18. * @property \Illuminate\Support\Carbon|null $deleted_at
  19. * @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\ImprovementType> $improvements
  20. * @property-read int|null $improvements_count
  21. * @property-read \App\Models\Client|null $originClient
  22. * @property-read \App\Models\Provider|null $originProvider
  23. * @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\ReviewImprovement> $reviewsImprovements
  24. * @property-read int|null $reviews_improvements_count
  25. * @property-read \App\Models\Schedule $schedule
  26. * @method static \Illuminate\Database\Eloquent\Builder<static>|Review newModelQuery()
  27. * @method static \Illuminate\Database\Eloquent\Builder<static>|Review newQuery()
  28. * @method static \Illuminate\Database\Eloquent\Builder<static>|Review onlyTrashed()
  29. * @method static \Illuminate\Database\Eloquent\Builder<static>|Review query()
  30. * @method static \Illuminate\Database\Eloquent\Builder<static>|Review whereComment($value)
  31. * @method static \Illuminate\Database\Eloquent\Builder<static>|Review whereCreatedAt($value)
  32. * @method static \Illuminate\Database\Eloquent\Builder<static>|Review whereDeletedAt($value)
  33. * @method static \Illuminate\Database\Eloquent\Builder<static>|Review whereId($value)
  34. * @method static \Illuminate\Database\Eloquent\Builder<static>|Review whereOrigin($value)
  35. * @method static \Illuminate\Database\Eloquent\Builder<static>|Review whereOriginId($value)
  36. * @method static \Illuminate\Database\Eloquent\Builder<static>|Review whereScheduleId($value)
  37. * @method static \Illuminate\Database\Eloquent\Builder<static>|Review whereStars($value)
  38. * @method static \Illuminate\Database\Eloquent\Builder<static>|Review whereUpdatedAt($value)
  39. * @method static \Illuminate\Database\Eloquent\Builder<static>|Review withTrashed(bool $withTrashed = true)
  40. * @method static \Illuminate\Database\Eloquent\Builder<static>|Review withoutTrashed()
  41. * @mixin \Eloquent
  42. */
  43. class Review extends Model
  44. {
  45. use HasFactory, SoftDeletes;
  46. protected $fillable = [
  47. 'schedule_id',
  48. 'origin',
  49. 'origin_id',
  50. 'stars',
  51. 'comment',
  52. ];
  53. protected $casts = [
  54. 'stars' => 'decimal:1',
  55. 'created_at' => 'datetime',
  56. 'updated_at' => 'datetime',
  57. 'deleted_at' => 'datetime',
  58. ];
  59. public function schedule(): BelongsTo
  60. {
  61. return $this->belongsTo(Schedule::class);
  62. }
  63. public function originProvider(): BelongsTo
  64. {
  65. return $this->belongsTo(Provider::class, 'origin_id');
  66. }
  67. public function originClient(): BelongsTo
  68. {
  69. return $this->belongsTo(Client::class, 'origin_id');
  70. }
  71. public function reviewsImprovements(): HasMany
  72. {
  73. return $this->hasMany(ReviewImprovement::class);
  74. }
  75. public function improvements(): BelongsToMany
  76. {
  77. return $this->belongsToMany(
  78. ImprovementType::class,
  79. 'reviews_improvements',
  80. 'review_id',
  81. 'improvement_type_id'
  82. )->withTimestamps();
  83. }
  84. }