'datetime', 'date_end' => 'datetime', ]; protected $fillable = [ 'title', 'text', 'picture_home', 'alt_text_picture_home', 'picture_news', 'alt_text_picture_news', 'date_start', 'date_end', 'on_top' ]; protected $translatable = [ 'title', 'text', 'picture_home', 'alt_text_picture_home', 'picture_news', 'alt_text_picture_news' ]; protected static function boot() { static::creating(function (Post $post) { if (is_a($post->picture_home,"SplFileInfo")) { $post->picture_home = Utils::storeImage($post->picture_home, $post->getTable()); } if (is_a($post->picture_news,"SplFileInfo")) { $post->picture_news = Utils::storeImage($post->picture_news, $post->getTable()); } }); static::updating(function (Post $post) { if (is_a($post->picture_home,"SplFileInfo")) { $post->picture_home = Utils::storeImage($post->picture_home, $post->getTable()); } if (is_a($post->picture_news,"SplFileInfo")) { $post->picture_news = Utils::storeImage($post->picture_news, $post->getTable()); } }); static::deleted(function (Post $post) { if ($post->picture_home) { $urlPicture = public_path() . $post->picture_home; if ($urlPicture) { if (File::exists($urlPicture)) { File::delete($urlPicture); } } } if ($post->picture_news) { $urlPicture = public_path() . $post->picture_news; if ($urlPicture) { if (File::exists($urlPicture)) { File::delete($urlPicture); } } } }); parent::boot(); } }