58 lines
1.5 KiB
PHP
58 lines
1.5 KiB
PHP
|
<?php
|
|||
|
|
|||
|
namespace App\Models;
|
|||
|
|
|||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|||
|
use Illuminate\Database\Eloquent\Model;
|
|||
|
use App\Helpers\ChineseNameConverter;
|
|||
|
|
|||
|
class Song extends Model
|
|||
|
{
|
|||
|
/** @use HasFactory<\Database\Factories\SongFactory> */
|
|||
|
use HasFactory;
|
|||
|
|
|||
|
protected $fillable = [
|
|||
|
'name',
|
|||
|
'adddate',
|
|||
|
'filename',
|
|||
|
'language_type',
|
|||
|
'db_change',
|
|||
|
'vocal',
|
|||
|
'situation',
|
|||
|
'copyright01',
|
|||
|
'copyright02',
|
|||
|
'note01',
|
|||
|
'note02',
|
|||
|
'note03',
|
|||
|
'note04',
|
|||
|
'enable',
|
|||
|
'unnamed_21',
|
|||
|
'simplified',
|
|||
|
'phonetic_abbr',
|
|||
|
'pinyin_abbr',
|
|||
|
];
|
|||
|
|
|||
|
|
|||
|
public function artists(){
|
|||
|
return $this->belongsToMany(Artist::class);
|
|||
|
}
|
|||
|
|
|||
|
public function categories(){
|
|||
|
return $this->belongsToMany(SongCategory::class);
|
|||
|
}
|
|||
|
|
|||
|
public function language(){
|
|||
|
return $this->belongsTo(SongLanguage::class, 'languageType', 'id');
|
|||
|
}
|
|||
|
protected static function booted()
|
|||
|
{
|
|||
|
// 無論是 creating 或 updating,都執行這段共用的邏輯
|
|||
|
static::saving(function ($song) {
|
|||
|
$simplified=ChineseNameConverter::convertToSimplified($song->name);// 繁體轉簡體
|
|||
|
$song->simplified = $simplified;
|
|||
|
$song->phonetic_abbr = ChineseNameConverter::getKTVZhuyinAbbr($simplified);// 注音符號
|
|||
|
$song->pinyin_abbr=ChineseNameConverter::getKTVPinyinAbbr($simplified);// 拼音首字母
|
|||
|
});
|
|||
|
}
|
|||
|
}
|