84 lines
2.0 KiB
PHP
84 lines
2.0 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\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Illuminate\Support\Str;
|
|
use MatanYadaev\EloquentSpatial\Objects\Point;
|
|
use MatanYadaev\EloquentSpatial\Objects\Polygon;
|
|
use MatanYadaev\EloquentSpatial\Traits\HasSpatial;
|
|
|
|
class DropOffPoint extends Model
|
|
{
|
|
use HasFactory, HasSpatial, HasTenant, SoftDeletes;
|
|
|
|
public const STATUS_ACTIVE = 'active';
|
|
|
|
public const STATUS_MAINTENANCE = 'maintenance';
|
|
|
|
public const STATUS_CLOSED = 'closed';
|
|
|
|
protected $fillable = [
|
|
'uuid',
|
|
'tenant_id',
|
|
'name',
|
|
'code',
|
|
'barangay_id',
|
|
'coordinates',
|
|
'geofence',
|
|
'address_line',
|
|
'capacity_kg',
|
|
'operating_hours',
|
|
'accepted_waste_types',
|
|
'status',
|
|
'photo_path',
|
|
'contact_person',
|
|
'contact_phone',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'coordinates' => Point::class,
|
|
'geofence' => Polygon::class,
|
|
'operating_hours' => 'array',
|
|
'accepted_waste_types' => 'array',
|
|
'capacity_kg' => 'integer',
|
|
];
|
|
}
|
|
|
|
public function getRouteKeyName(): string
|
|
{
|
|
return 'uuid';
|
|
}
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::creating(function (self $dop): void {
|
|
if (empty($dop->uuid)) {
|
|
$dop->uuid = (string) Str::uuid();
|
|
}
|
|
});
|
|
}
|
|
|
|
public function barangay(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Barangay::class);
|
|
}
|
|
|
|
public function capacityLogs(): HasMany
|
|
{
|
|
return $this->hasMany(DropOffCapacityLog::class);
|
|
}
|
|
|
|
public function households(): HasMany
|
|
{
|
|
return $this->hasMany(Household::class, 'assigned_drop_off_point_id');
|
|
}
|
|
}
|