You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.4 KiB
67 lines
1.4 KiB
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class Banner extends Model
|
|
{
|
|
use SoftDeletes;
|
|
|
|
public const TYPE_COURSE = 'course';
|
|
|
|
public const TYPE_ACTIVITY = 'activity';
|
|
|
|
public const TYPE_NEWS = 'news';
|
|
|
|
public const TYPE_CUSTOM = 'custom';
|
|
|
|
protected $fillable = [
|
|
'type',
|
|
'course_id',
|
|
'activity_id',
|
|
'news_id',
|
|
'title',
|
|
'cover_url',
|
|
'content_html',
|
|
'sort',
|
|
'status',
|
|
];
|
|
|
|
protected $casts = [
|
|
'course_id' => 'integer',
|
|
'activity_id' => 'integer',
|
|
'news_id' => 'integer',
|
|
'sort' => 'integer',
|
|
'status' => 'integer',
|
|
];
|
|
|
|
public function course(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Course::class);
|
|
}
|
|
|
|
public function activity(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Activity::class);
|
|
}
|
|
|
|
public function news(): BelongsTo
|
|
{
|
|
return $this->belongsTo(News::class);
|
|
}
|
|
|
|
public static function typeLabel(string $type): string
|
|
{
|
|
return match ($type) {
|
|
self::TYPE_COURSE => '课程',
|
|
self::TYPE_ACTIVITY => '活动',
|
|
self::TYPE_NEWS => '资讯',
|
|
self::TYPE_CUSTOM => '自定义',
|
|
default => $type,
|
|
};
|
|
}
|
|
}
|