Badgeable.php 506B

123456789101112131415161718192021222324252627
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class Badgeable extends Model
  5. {
  6. //
  7. protected $guarded = ["id"];
  8. protected $cast = ["award_type" => 'integer'];
  9. public function badge()
  10. {
  11. return $this->belongsTo(Badge::class);
  12. }
  13. public function getAwardTypeNameAttribute(): string
  14. {
  15. return match($this->award_type) {
  16. 1 => '主要標籤',
  17. 2 => '次要標籤',
  18. default => '未知',
  19. };
  20. }
  21. }