Files
fuel-price/app/Models/Station.php

57 lines
1.9 KiB
PHP

<?php
namespace App\Models;
use App\Enums\FuelType;
use Database\Factories\StationFactory;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
#[Fillable([
'node_id', 'trading_name', 'brand_name', 'is_same_trading_and_brand',
'is_supermarket', 'is_motorway_service_station', 'is_supermarket_service_station',
'temporary_closure', 'permanent_closure', 'permanent_closure_date',
'public_phone_number', 'address_line_1', 'address_line_2', 'city',
'county', 'country', 'postcode', 'lat', 'lng',
'amenities', 'opening_times', 'fuel_types', 'last_seen_at',
])]
class Station extends Model
{
/** @use HasFactory<StationFactory> */
use HasFactory;
public $timestamps = false;
protected $primaryKey = 'node_id';
public $incrementing = false;
protected $keyType = 'string';
protected function casts(): array
{
return [
'is_same_trading_and_brand' => 'boolean',
'is_supermarket' => 'boolean',
'is_motorway_service_station' => 'boolean',
'is_supermarket_service_station' => 'boolean',
'temporary_closure' => 'boolean',
'permanent_closure' => 'boolean',
'permanent_closure_date' => 'date',
'amenities' => 'array',
'opening_times' => 'array',
'fuel_types' => 'array',
'last_seen_at' => 'datetime',
];
}
public function currentPrices(): HasMany
{
return $this->hasMany(StationPriceCurrent::class, 'station_id', 'node_id');
}
public function prices(): HasMany
{
return $this->hasMany(StationPrice::class, 'station_id', 'node_id');
}
}