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.
57 lines
1.2 KiB
57 lines
1.2 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';
|
||
|
|
|
||
|
|
public const TYPE_CUSTOM = 'custom';
|
||
|
|
|
||
|
|
protected $fillable = [
|
||
|
|
'type',
|
||
|
|
'course_id',
|
||
|
|
'activity_id',
|
||
|
|
'title',
|
||
|
|
'cover_url',
|
||
|
|
'content_html',
|
||
|
|
'sort',
|
||
|
|
'status',
|
||
|
|
];
|
||
|
|
|
||
|
|
protected $casts = [
|
||
|
|
'course_id' => 'integer',
|
||
|
|
'activity_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 static function typeLabel(string $type): string
|
||
|
|
{
|
||
|
|
return match ($type) {
|
||
|
|
self::TYPE_COURSE => '课程',
|
||
|
|
self::TYPE_ACTIVITY => '活动',
|
||
|
|
self::TYPE_CUSTOM => '自定义',
|
||
|
|
default => $type,
|
||
|
|
};
|
||
|
|
}
|
||
|
|
}
|