'datetime', 'date_end' => 'datetime', ]; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'title', 'text', 'link_label', 'link', 'link_new_tab', 'slider_id', 'picture', 'alt_text_picture', 'date_start', 'date_end' ]; /** * The attributes that are translatable. * * @var array */ public $translatable = [ 'title', 'text', 'picture', 'link', 'link_label', 'alt_text_picture' ]; /** * Perform any actions required after the model boots. * * @return void */ protected static function boot() { static::creating(function (Slide $slide) { if (is_a($slide->picture, "SplFileInfo")) { $slide->picture = Utils::storeImage($slide->picture, $slide->getTable()); } }); static::updating(function (Slide $slide) { if (is_a($slide->picture, "SplFileInfo")) { $slide->picture = Utils::storeImage($slide->picture, $slide->getTable()); } }); static::deleted(function (Slide $slide) { if ($slide->picture) { $urlPicture = public_path() . $slide->picture; if ($urlPicture) { if (File::exists($urlPicture)) { File::delete($urlPicture); } } } }); parent::boot(); } /** * BelongsTo slider relation * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function slider() { return $this->belongsTo(Slider::class); } }