完善功能
This commit is contained in:
52
web10/app/Models/Ad.php
Normal file
52
web10/app/Models/Ad.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user