| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- namespace App;
- use Exception;
- /**
- * Class Location
- * @property int $id
- * @property int $customer_id
- * @property int $address_id
- * @property string $name
- * @property string $phone
- * @property string $fax
- * @property string $email
- * @property string $dts_created
- * @property string $dts_updated
- * @property string $dts_deleted
- */
- class Location extends Model {
- protected static $table = "location";
- protected static $idField = "id";
- protected static $fillableFields = ["customer_id", "address_id", "name", "phone", "fax", "email", "dts_created", "dts_updated", "dts_deleted"];
- /**
- * @return Customer
- * @throws Exception
- */
- public function getCustomer(): Customer {
- return Customer::get($this->customer_id);
- }
- /**
- * @return Address
- * @throws Exception
- */
- public function getAddress(): Address {
- $address = Address::get($this->address_id);
- return $address ?: new Address();
- }
- public function getSlug(): string {
- return Util::slug("$this->name $this->id");
- }
- /**
- * @return string
- * @throws Exception
- */
- public function getUrl(): string {
- return sprintf("/locations/%s", $this->getSlug());
- }
- /**
- * @return string
- * @throws Exception
- */
- public function getDisplayName(): string {
- $customer = $this->getCustomer();
- return sprintf("%s - %s", $customer->name, $this->name);
- }
- }
|