You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace App\Models\Locale;
  3. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  4. use Illuminate\Database\Eloquent\Relations\HasMany;
  5. use Illuminate\Support\Collection;
  6. use Squire\Model;
  7. /**
  8. * @property int $id
  9. * @property string $name
  10. * @property string $country_id
  11. * @property string $country_name
  12. * @property string $state_code
  13. * @property float $latitude
  14. * @property float $longitude
  15. */
  16. class State extends Model
  17. {
  18. public static array $schema = [
  19. 'id' => 'integer',
  20. 'name' => 'string',
  21. 'country_id' => 'string',
  22. 'country_name' => 'string',
  23. 'state_code' => 'string',
  24. 'latitude' => 'float',
  25. 'longitude' => 'float',
  26. ];
  27. public static function getStateOptions(?string $code = null): Collection
  28. {
  29. if ($code === null) {
  30. return collect();
  31. }
  32. return self::where('country_id', $code)->get()->pluck('name', 'id');
  33. }
  34. public function country(): BelongsTo
  35. {
  36. return $this->belongsTo(Country::class, 'country_id', 'id');
  37. }
  38. public function cities(): HasMany
  39. {
  40. return $this->hasMany(City::class, 'state_id', 'id');
  41. }
  42. }