Page::class ]; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'title', 'subtitle', 'text', 'picture', 'alt_text_picture', ]; /** * The attributes that are translatable. * * @var array */ public $translatable = [ 'title', 'subtitle', 'text', 'picture', 'alt_text_picture', ]; /** * Perform any actions required after the model boots. * * @return void */ protected static function boot() { static::creating(function (Moment $moment) { if (is_a($moment->picture, "SplFileInfo")) { $moment->picture = Utils::storeImage($moment->picture, $moment->getTable()); } }); static::updating(function (Moment $moment) { if (is_a($moment->picture, "SplFileInfo")) { $moment->picture = Utils::storeImage($moment->picture, $moment->getTable()); } }); static::deleted(function (Moment $moment) { if ($moment->picture) { $urlPicture = public_path() . $moment->picture; if ($urlPicture) { if (File::exists($urlPicture)) { File::delete($urlPicture); } } } }); parent::boot(); } }