1234567891011121314151617181920212223242526272829303132 |
- <?php
-
- namespace App\Models;
-
- use Illuminate\Database\Eloquent\Casts\Attribute;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\SoftDeletes;
- use Illuminate\Support\Facades\Storage;
- use App\Models\News;
- use Spatie\Translatable\HasTranslations;
-
- class NewsPhoto extends Model
- {
- use HasFactory, HasTranslations;
-
- protected $guarded = ['id'];
- public $timestamps = false;
- protected $appends = ['news_photo_img'];
- public $translatable = ['image_alt'];
-
- public function news(){
- return $this->belongsTo(News::class);
- }
- protected function newsPhotoImg(): Attribute
- {
- return Attribute::make(
- get: fn ($value) => is_null($this->image_url) ? null :Storage::disk('public')->url($this->image_url),
- );
- }
- }
|