Files
fuel-price/app/Models/UserNotificationPreference.php
Ovidiu U 783297694c fix: model audit cleanups (primaryKey, fuel_type cast, cadence cache)
- 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>
2026-04-29 18:32:55 +01:00

52 lines
1.2 KiB
PHP

<?php
namespace App\Models;
use App\Enums\FuelType;
use Database\Factories\UserNotificationPreferenceFactory;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class UserNotificationPreference extends Model
{
/** @use HasFactory<UserNotificationPreferenceFactory> */
use HasFactory;
protected $fillable = [
'user_id',
'channel',
'fuel_type',
'enabled',
];
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function scopeEnabled(Builder $query): void
{
$query->where('enabled', true);
}
public function scopeForChannel(Builder $query, string $channel): void
{
$query->where('channel', $channel);
}
public function scopeForFuelType(Builder $query, string $fuelType): void
{
$query->where('fuel_type', $fuelType);
}
protected function casts(): array
{
return [
'enabled' => 'boolean',
'fuel_type' => FuelType::class,
];
}
}