generated from liutk/owl-admin-base
39 lines
974 B
PHP
39 lines
974 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use EloquentFilter\Filterable;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Support\Str;
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
|
|
class Timeline extends Model
|
|
{
|
|
use HasFactory;
|
|
use Filterable;
|
|
|
|
protected function serializeDate(\DateTimeInterface $date)
|
|
{
|
|
return $date->format('Y-m-d H:i:s');
|
|
}
|
|
|
|
protected function coverUrl():Attribute {
|
|
return Attribute::make(
|
|
get: fn($value) => $this->cover ? (Str::startsWith($this->cover, ['http://', 'https://']) ? $this->cover : Storage::url($this->cover)) : null,
|
|
);
|
|
}
|
|
|
|
public function scopeShow($q){
|
|
$q->where('is_enable', true);
|
|
}
|
|
|
|
public function scopeSort($q)
|
|
{
|
|
$q->orderBy('awarded_date', 'desc')
|
|
->orderBy('sort', 'asc')
|
|
->orderBy('created_at', 'desc');
|
|
}
|
|
}
|