59 lines
1.2 KiB
PHP
59 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Tenancy\HasTenant;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Illuminate\Support\Str;
|
|
|
|
use MatanYadaev\EloquentSpatial\Objects\Polygon;
|
|
|
|
class ServiceArea extends Model
|
|
{
|
|
use HasFactory, HasTenant, SoftDeletes;
|
|
|
|
public const STATUS_ACTIVE = 'active';
|
|
|
|
public const STATUS_INACTIVE = 'inactive';
|
|
|
|
protected $fillable = [
|
|
'uuid',
|
|
'tenant_id',
|
|
'name',
|
|
'code',
|
|
'status',
|
|
'description',
|
|
'boundary',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'boundary' => Polygon::class,
|
|
];
|
|
}
|
|
|
|
public function getRouteKeyName(): string
|
|
{
|
|
return 'uuid';
|
|
}
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::creating(function (self $area): void {
|
|
if (empty($area->uuid)) {
|
|
$area->uuid = (string) Str::uuid();
|
|
}
|
|
});
|
|
}
|
|
|
|
public function barangays(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(Barangay::class, 'service_area_barangay')
|
|
->withTimestamps();
|
|
}
|
|
}
|