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

2 weeks ago
<?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';
3 days ago
public const TYPE_NEWS = 'news';
2 weeks ago
public const TYPE_CUSTOM = 'custom';
protected $fillable = [
'type',
'course_id',
'activity_id',
3 days ago
'news_id',
2 weeks ago
'title',
'cover_url',
'content_html',
'sort',
'status',
];
protected $casts = [
'course_id' => 'integer',
'activity_id' => 'integer',
3 days ago
'news_id' => 'integer',
2 weeks ago
'sort' => 'integer',
'status' => 'integer',
];
public function course(): BelongsTo
{
return $this->belongsTo(Course::class);
}
public function activity(): BelongsTo
{
return $this->belongsTo(Activity::class);
}
3 days ago
public function news(): BelongsTo
{
return $this->belongsTo(News::class);
}
2 weeks ago
public static function typeLabel(string $type): string
{
return match ($type) {
self::TYPE_COURSE => '课程',
self::TYPE_ACTIVITY => '活动',
3 days ago
self::TYPE_NEWS => '资讯',
2 weeks ago
self::TYPE_CUSTOM => '自定义',
default => $type,
};
}
}