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;
|
|
|
|
|
|
2026-08-18 22:23:20 +03:30
|
|
|
private static ?bool $productIdColumnExists = null;
|
|
|
|
|
|
2026-01-24 14:03:11 +00:00
|
|
|
protected $fillable = [
|
|
|
|
|
'customer_id',
|
2026-08-18 22:23:20 +03:30
|
|
|
'product_id',
|
2026-01-24 14:03:11 +00:00
|
|
|
'target_price',
|
|
|
|
|
'price_condition',
|
|
|
|
|
'action',
|
|
|
|
|
'is_active',
|
|
|
|
|
'triggered_at',
|
|
|
|
|
];
|
|
|
|
|
protected $casts = [
|
|
|
|
|
"is_active" => "boolean",
|
|
|
|
|
];
|
2026-08-18 22:23:20 +03:30
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
2026-08-18 22:23:20 +03:30
|
|
|
|
|
|
|
|
public function product()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Product::class);
|
|
|
|
|
}
|
2026-01-24 14:03:11 +00:00
|
|
|
}
|