- StationPriceCurrent: $primaryKey was null; set to 'station_id' + keyType string so Eloquent has a sensible default for save() / find() paths. - UserNotificationPreference: add FuelType enum cast on fuel_type so it hydrates as an enum like every other price model. - Plan::resolveCadenceForUser: cache for 1h under the same plans tag as resolveForUser; HandleStripeWebhook busts both keys on subscription events. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
48 lines
1.2 KiB
PHP
48 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\FuelType;
|
|
use Database\Factories\StationPriceCurrentFactory;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
#[Fillable(['station_id', 'fuel_type', 'price_pence', 'price_effective_at', 'price_reported_at', 'recorded_at'])]
|
|
class StationPriceCurrent extends Model
|
|
{
|
|
/** @use HasFactory<StationPriceCurrentFactory> */
|
|
use HasFactory;
|
|
|
|
protected $table = 'station_prices_current';
|
|
|
|
public $timestamps = false;
|
|
|
|
protected $primaryKey = 'station_id';
|
|
|
|
protected $keyType = 'string';
|
|
|
|
public $incrementing = false;
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'fuel_type' => FuelType::class,
|
|
'price_effective_at' => 'datetime',
|
|
'price_reported_at' => 'datetime',
|
|
'recorded_at' => 'datetime',
|
|
];
|
|
}
|
|
|
|
public function station(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Station::class, 'station_id', 'node_id');
|
|
}
|
|
|
|
public function priceInPence(): float
|
|
{
|
|
return $this->price_pence / 100;
|
|
}
|
|
}
|