2025-04-25 09:33:28 +08:00
|
|
|
|
<?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',
|
|
|
|
|
];
|
|
|
|
|
|
2025-04-29 14:18:07 +08:00
|
|
|
|
public function users(){
|
|
|
|
|
return $this->belongsToMany(User::class, 'user_song')->withTimestamps();
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-25 18:21:20 +08:00
|
|
|
|
public function str_artists(){
|
|
|
|
|
return $this->artists->pluck('name')->implode(', ');
|
|
|
|
|
}
|
2025-04-25 09:33:28 +08:00
|
|
|
|
public function artists(){
|
|
|
|
|
return $this->belongsToMany(Artist::class);
|
|
|
|
|
}
|
2025-04-25 18:21:20 +08:00
|
|
|
|
public function str_categories(){
|
|
|
|
|
return $this->categories->pluck('name')->implode(', ');
|
|
|
|
|
}
|
2025-04-25 09:33:28 +08:00
|
|
|
|
public function categories(){
|
|
|
|
|
return $this->belongsToMany(SongCategory::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function language(){
|
2025-04-25 18:21:20 +08:00
|
|
|
|
return $this->belongsTo(SongLanguage::class, 'language_type', 'id');
|
2025-04-25 09:33:28 +08:00
|
|
|
|
}
|
|
|
|
|
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);// 拼音首字母
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|