DiaryMood.php 514 B

12345678910111213141516171819
  1. <?php
  2. namespace App\Models;
  3. class DiaryMood extends SoftBaseModel
  4. {
  5. protected $casts = ['tag'=>'array'];
  6. protected $appends = ['tags'];
  7. public function level(){
  8. return $this->belongsTo(DiaryMoodLevel::class, 'level_id', 'id');
  9. }
  10. public function getTagsAttribute()
  11. {
  12. $tagArr = json_decode($this->attributes['tag'], TRUE);
  13. return $tagArr ? DiaryMoodTag::whereIn('id', $tagArr)->orderByRaw('`rank` desc, `id` desc')->get(['id','name','color']) : [];
  14. }
  15. }