Location.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace App;
  3. use Exception;
  4. /**
  5. * Class Location
  6. * @property int $id
  7. * @property int $customer_id
  8. * @property int $address_id
  9. * @property string $name
  10. * @property string $phone
  11. * @property string $fax
  12. * @property string $email
  13. * @property string $dts_created
  14. * @property string $dts_updated
  15. * @property string $dts_deleted
  16. */
  17. class Location extends Model {
  18. protected static $table = "location";
  19. protected static $idField = "id";
  20. protected static $fillableFields = ["customer_id", "address_id", "name", "phone", "fax", "email", "dts_created", "dts_updated", "dts_deleted"];
  21. /**
  22. * @return Customer
  23. * @throws Exception
  24. */
  25. public function getCustomer(): Customer {
  26. return Customer::get($this->customer_id);
  27. }
  28. /**
  29. * @return Address
  30. * @throws Exception
  31. */
  32. public function getAddress(): Address {
  33. $address = Address::get($this->address_id);
  34. return $address ?: new Address();
  35. }
  36. public function getSlug(): string {
  37. return Util::slug("$this->name $this->id");
  38. }
  39. /**
  40. * @return string
  41. * @throws Exception
  42. */
  43. public function getUrl(): string {
  44. return sprintf("/locations/%s", $this->getSlug());
  45. }
  46. }