12345678910111213141516171819 |
- <?php
- namespace App\Models;
- class DiaryMood extends SoftBaseModel
- {
- protected $casts = ['tag'=>'array'];
- protected $appends = ['tags'];
-
- public function level(){
- return $this->belongsTo(DiaryMoodLevel::class, 'level_id', 'id');
- }
-
- public function getTagsAttribute()
- {
- $tagArr = json_decode($this->attributes['tag'], TRUE);
- return $tagArr ? DiaryMoodTag::whereIn('id', $tagArr)->orderByRaw('`rank` desc, `id` desc')->get(['id','name','color']) : [];
- }
- }
|