| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 | 
							- <?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 Spatie\Translatable\HasTranslations;
 - use App\Models\News;
 - 
 - class NewsParagraph extends Model
 - {
 -     use HasFactory, HasTranslations;
 -     CONST IMAGE = 1;
 -     CONST TEXT = 2;
 -     CONST VIDEO = 3;
 - 
 -     protected $guarded = ['id'];
 -     public $timestamps = false;
 -     protected $appends = ['paragraph_img', 'paragraph_video_img', 'paragraph_video_type', 'paragraph_video_url'];
 -     public $translatable = ['text_content', 'image_alt'];
 - 
 -     public function news(){
 -         return $this->belongsTo(News::class);
 -     }
 - 
 -     public function contentType()
 -     {
 -         switch ($this->paragraph_type){
 -             case 1:
 -                 return "image";
 -             case 2:
 -                 return "text";
 -             case 3:
 -                 return "video";
 -             default:
 -                 return "";
 -         }
 -     }
 -     protected function paragraphImg(): Attribute
 -     {
 -         return Attribute::make(
 -             get: fn ($value) => is_null($this->image_url) ? null :Storage::disk('public')->url($this->image_url),
 -         );
 -     }
 -     protected function paragraphVideoType(): Attribute
 -     {
 -         return Attribute::make(
 -             get: fn ($value) => ($this->paragraph_type == 3) ? ($this->attributes["video_type"] == 1 ? "url" : "upload") : null,
 -         );
 -     }
 -     protected function paragraphVideoImg(): Attribute
 -     {
 -         return Attribute::make(
 -             get: fn ($value) => is_null($this->video_img) ? null :Storage::disk('public')->url($this->video_img),
 -         );
 -     }
 -     protected function paragraphVideoUrl(): Attribute
 -     {
 -         return Attribute::make(
 -             get: fn ($value) => ($this->attributes["video_type"] == 2) ? Storage::disk('public')->url($this->attributes["video_url"]) : $this->attributes["link"],
 -         );
 -     }
 - }
 
 
  |