Order.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace App\Models;
  3. use App\Models\Dictionary\Area;
  4. use App\Models\Dictionary\District;
  5. use Illuminate\Database\Eloquent\Model;
  6. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  7. use Illuminate\Database\Eloquent\Relations\BelongsToMany;
  8. use Illuminate\Support\Facades\DB;
  9. class Order extends Model
  10. {
  11. const DEFAULT_SORT_BY = 'created_at';
  12. protected $fillable = [
  13. 'user_id',
  14. 'district_id',
  15. 'area_id',
  16. 'object_address',
  17. 'object_type_id',
  18. 'contract_date',
  19. 'contract_number',
  20. 'comment',
  21. 'installation_date',
  22. 'brigadier_id',
  23. 'order_status_id',
  24. 'tg_group_name',
  25. 'tg_group_link',
  26. ];
  27. /**
  28. * @return BelongsToMany
  29. */
  30. public function products(): BelongsToMany
  31. {
  32. return $this->belongsToMany(Product::class, 'order_product', 'order_id', 'product_id');
  33. }
  34. public function user(): BelongsTo
  35. {
  36. return $this->belongsTo(User::class, 'user_id', 'id');
  37. }
  38. public function district(): BelongsTo
  39. {
  40. return $this->belongsTo(District::class);
  41. }
  42. public function area(): BelongsTo
  43. {
  44. return $this->belongsTo(Area::class);
  45. }
  46. public function objectType(): BelongsTo
  47. {
  48. return $this->belongsTo(ObjectType::class);
  49. }
  50. public function brigadier(): BelongsTo
  51. {
  52. return $this->belongsTo(Brigadier::class);
  53. }
  54. public function orderStatus(): BelongsTo
  55. {
  56. return $this->belongsTo(OrderStatus::class);
  57. }
  58. }