CustomSchedule.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  5. use Illuminate\Database\Eloquent\Relations\HasMany;
  6. use Illuminate\Database\Eloquent\Relations\HasOne;
  7. use Illuminate\Database\Eloquent\SoftDeletes;
  8. /**
  9. * @property int $id
  10. * @property int $schedule_id
  11. * @property string $address_type
  12. * @property int $service_type_id
  13. * @property string|null $description
  14. * @property numeric $min_price
  15. * @property numeric $max_price
  16. * @property bool $offers_meal
  17. * @property \Illuminate\Support\Carbon|null $created_at
  18. * @property \Illuminate\Support\Carbon|null $updated_at
  19. * @property \Illuminate\Support\Carbon|null $deleted_at
  20. * @property-read \App\Models\Schedule $schedule
  21. * @property-read \App\Models\ServiceType|null $serviceType
  22. * @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\CustomScheduleSpeciality> $specialities
  23. * @property-read int|null $specialities_count
  24. * @method static \Illuminate\Database\Eloquent\Builder<static>|CustomSchedule newModelQuery()
  25. * @method static \Illuminate\Database\Eloquent\Builder<static>|CustomSchedule newQuery()
  26. * @method static \Illuminate\Database\Eloquent\Builder<static>|CustomSchedule onlyTrashed()
  27. * @method static \Illuminate\Database\Eloquent\Builder<static>|CustomSchedule query()
  28. * @method static \Illuminate\Database\Eloquent\Builder<static>|CustomSchedule whereAddressType($value)
  29. * @method static \Illuminate\Database\Eloquent\Builder<static>|CustomSchedule whereCreatedAt($value)
  30. * @method static \Illuminate\Database\Eloquent\Builder<static>|CustomSchedule whereDeletedAt($value)
  31. * @method static \Illuminate\Database\Eloquent\Builder<static>|CustomSchedule whereDescription($value)
  32. * @method static \Illuminate\Database\Eloquent\Builder<static>|CustomSchedule whereId($value)
  33. * @method static \Illuminate\Database\Eloquent\Builder<static>|CustomSchedule whereMaxPrice($value)
  34. * @method static \Illuminate\Database\Eloquent\Builder<static>|CustomSchedule whereMinPrice($value)
  35. * @method static \Illuminate\Database\Eloquent\Builder<static>|CustomSchedule whereOffersMeal($value)
  36. * @method static \Illuminate\Database\Eloquent\Builder<static>|CustomSchedule whereScheduleId($value)
  37. * @method static \Illuminate\Database\Eloquent\Builder<static>|CustomSchedule whereServiceTypeId($value)
  38. * @method static \Illuminate\Database\Eloquent\Builder<static>|CustomSchedule whereUpdatedAt($value)
  39. * @method static \Illuminate\Database\Eloquent\Builder<static>|CustomSchedule withTrashed(bool $withTrashed = true)
  40. * @method static \Illuminate\Database\Eloquent\Builder<static>|CustomSchedule withoutTrashed()
  41. * @mixin \Eloquent
  42. */
  43. class CustomSchedule extends Model
  44. {
  45. use SoftDeletes;
  46. protected $fillable = [
  47. 'schedule_id',
  48. 'address_type',
  49. 'service_type_id',
  50. 'description',
  51. 'min_price',
  52. 'max_price',
  53. 'offers_meal',
  54. ];
  55. protected $casts = [
  56. 'min_price' => 'decimal:2',
  57. 'max_price' => 'decimal:2',
  58. 'offers_meal' => 'boolean',
  59. ];
  60. public function schedule(): BelongsTo
  61. {
  62. return $this->belongsTo(Schedule::class);
  63. }
  64. public function serviceType(): HasOne
  65. {
  66. return $this->hasOne(ServiceType::class, 'id', 'service_type_id')->select('id', 'description');
  67. }
  68. public function specialities(): HasMany
  69. {
  70. return $this->hasMany(CustomScheduleSpeciality::class, 'custom_schedule_id', 'id')->leftJoin('specialities', 'custom_schedules_specialities.speciality_id', '=', 'specialities.id')
  71. ->select('specialities.id', 'specialities.description', 'custom_schedules_specialities.custom_schedule_id');
  72. }
  73. }