Banner.php 837B

123456789101112131415161718192021222324252627282930313233343536
  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 Banner extends Model
  8. {
  9. use HasTranslations;
  10. //
  11. protected $guarded = ["id"];
  12. public $translatable = ['title', 'content', 'img_alt'];
  13. public $appends = [
  14. "img_url_link", "mobile_img_link"
  15. ];
  16. protected function imgUrlLink(): Attribute
  17. {
  18. return Attribute::make(
  19. get: fn ($value) => is_null($this->img_url) ? null :Storage::url($this->img_url),
  20. );
  21. }
  22. protected function mobileImgLink(): Attribute
  23. {
  24. return Attribute::make(
  25. get: fn ($value) => is_null($this->mobile_img) ? null :Storage::url($this->mobile_img),
  26. );
  27. }
  28. }