53 lines
987 B
PHP
53 lines
987 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Ad extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'ad_slot_id',
|
|
'title',
|
|
'image',
|
|
'description',
|
|
'link_url',
|
|
'link_target',
|
|
'product_id',
|
|
'starts_at',
|
|
'ends_at',
|
|
'sort',
|
|
'is_active',
|
|
'view_count',
|
|
'click_count',
|
|
];
|
|
|
|
protected $casts = [
|
|
'is_active' => 'boolean',
|
|
'starts_at' => 'datetime',
|
|
'ends_at' => 'datetime',
|
|
];
|
|
|
|
public function adSlot()
|
|
{
|
|
return $this->belongsTo(AdSlot::class);
|
|
}
|
|
|
|
public function product()
|
|
{
|
|
return $this->belongsTo(Product::class);
|
|
}
|
|
|
|
public function getTargetUrl(): ?string
|
|
{
|
|
if ($this->product) {
|
|
return route('products.show', $this->product->slug);
|
|
}
|
|
|
|
return $this->link_url;
|
|
}
|
|
}
|