drop_off_points (with SPATIAL INDEX on coordinates) +
drop_off_capacity_logs. Public nearby query via ST_Distance_Sphere
returns DOPs sorted by distance with distance_meters in payload.
Admin CRUD plus capacity-log endpoint. Household creation auto-assigns
to the nearest active DOP within 25km; resident can re-run the lookup
via POST /households/{uuid}/reassign-drop-off.
97 feature tests passing.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
77 lines
1.8 KiB
PHP
77 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
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\Traits\HasSpatial;
|
|
|
|
class DropOffPoint extends Model
|
|
{
|
|
use HasFactory, HasSpatial, SoftDeletes;
|
|
|
|
public const STATUS_ACTIVE = 'active';
|
|
public const STATUS_MAINTENANCE = 'maintenance';
|
|
public const STATUS_CLOSED = 'closed';
|
|
|
|
protected $fillable = [
|
|
'uuid',
|
|
'name',
|
|
'code',
|
|
'barangay_id',
|
|
'coordinates',
|
|
'address_line',
|
|
'capacity_kg',
|
|
'operating_hours',
|
|
'accepted_waste_types',
|
|
'status',
|
|
'photo_path',
|
|
'contact_person',
|
|
'contact_phone',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'coordinates' => Point::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');
|
|
}
|
|
}
|