53 lines
1.3 KiB
PHP
53 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Dcat\Admin\Admin;
|
|
use EloquentFilter\Filterable;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Dcat\Admin\Traits\HasDateTimeFormatter;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
class FriendLink extends Model
|
|
{
|
|
use HasFactory, HasDateTimeFormatter, Filterable;
|
|
|
|
public const TYPE_LINK = 1; //链接
|
|
|
|
public const TYPE_VIDEO = 2; //视频
|
|
|
|
public const TYPE_ARTICLE = 3; //文章
|
|
|
|
protected $fillable = [
|
|
'name', 'type', 'content', 'sort', 'is_recommend', 'is_show'
|
|
];
|
|
|
|
public static function typeMap()
|
|
{
|
|
return [
|
|
self::TYPE_LINK => '链接',
|
|
self::TYPE_VIDEO => '视频',
|
|
self::TYPE_ARTICLE => '文章'
|
|
];
|
|
}
|
|
|
|
public function typeLabel()
|
|
{
|
|
$color = match ($this->type) {
|
|
static::TYPE_LINK => 'green',
|
|
static::TYPE_VIDEO => 'primary',
|
|
static::TYPE_ARTICLE => 'warning'
|
|
};
|
|
|
|
$background = Admin::color()->get($color, $color);
|
|
|
|
$name = static::typeMap()[$this->type] ?? '未知';
|
|
|
|
return "<span class='label' style='background: $background;'>{$name}</span>";
|
|
}
|
|
|
|
public function scopeSort($q){
|
|
return $q->orderBy('sort', 'desc')->orderBy('created_at', 'desc');
|
|
}
|
|
}
|