Files

55 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2026-01-24 14:03:11 +00:00
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class PriceTrigger extends Model
{
use HasFactory, SoftDeletes;
private static ?bool $productIdColumnExists = null;
2026-01-24 14:03:11 +00:00
protected $fillable = [
'customer_id',
'product_id',
2026-01-24 14:03:11 +00:00
'target_price',
'price_condition',
'action',
'is_active',
'triggered_at',
];
protected $casts = [
"is_active" => "boolean",
];
public static function hasProductIdColumn(): bool
{
if (static::$productIdColumnExists !== null) {
return static::$productIdColumnExists;
}
try {
static::$productIdColumnExists = \Illuminate\Support\Facades\Schema::hasColumn(
(new static)->getTable(),
'product_id'
);
} catch (\Throwable) {
static::$productIdColumnExists = false;
}
return static::$productIdColumnExists;
}
2026-01-24 14:03:11 +00:00
public function customer()
{
return $this->belongsTo(Customer::class);
}
public function product()
{
return $this->belongsTo(Product::class);
}
2026-01-24 14:03:11 +00:00
}