Location.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace App;
  3. use App\Enums\AruStatuses;
  4. use App\Traits\DateTimeTrait;
  5. use App\Traits\SoftDeleteTrait;
  6. use Exception;
  7. /**
  8. * Class Location
  9. * @property int $id
  10. * @property int $customer_id
  11. * @property int $address_id
  12. * @property string $name
  13. * @property string $phone
  14. * @property string $fax
  15. * @property string $email
  16. * @property string $contact_name
  17. * @property string $contact_phone
  18. * @property string $contact_email
  19. */
  20. class Location extends Model {
  21. protected static $table = "location";
  22. protected static $idField = "id";
  23. protected static $fillableFields = [
  24. "customer_id", "address_id",
  25. "name", "phone", "fax", "email",
  26. "contact_name", "contact_phone", "contact_email",
  27. "dts_created", "dts_updated", "dts_deleted"
  28. ];
  29. use DateTimeTrait;
  30. use SoftDeleteTrait;
  31. /**
  32. * @return Customer
  33. * @throws Exception
  34. */
  35. public function getCustomer(): Customer {
  36. return Customer::get($this->customer_id);
  37. }
  38. /**
  39. * @return Address
  40. * @throws Exception
  41. */
  42. public function getAddress(): Address {
  43. $address = Address::get($this->address_id);
  44. return $address ?: new Address();
  45. }
  46. public function getSlug(): string {
  47. return Util::slug("$this->name $this->id");
  48. }
  49. /**
  50. * @return string
  51. * @throws Exception
  52. */
  53. public function getUrl(): string {
  54. return sprintf("/locations/%s/update", $this->getSlug());
  55. }
  56. /**
  57. * @return string
  58. * @throws Exception
  59. */
  60. public function getDisplayName(): string {
  61. $customer = $this->getCustomer();
  62. return sprintf("%s - %s", $customer->name, $this->name);
  63. }
  64. }