Badge.php 691B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Casts\Attribute;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Support\Facades\Storage;
  6. use Spatie\Translatable\HasTranslations;
  7. class Badge extends Model
  8. {
  9. use HasTranslations;
  10. protected $guarded = ["id"];
  11. public $translatable = ["title", "img_alt"];
  12. protected $appends = ["img_url_link"];
  13. protected function imgUrlLink(): Attribute
  14. {
  15. return Attribute::make(
  16. get: fn ($value) => is_null($this->ing_url) ? null :Storage::url($this->ing_url),
  17. );
  18. }
  19. public function projects()
  20. {
  21. return $this->morphedByMany(Project::class, 'badgeable');
  22. }
  23. }