belongsTo(SectionPage::class, 'section_id'); } protected static function booted(): void { static::creating(function (self $picto) { $picto->picture = FileStorageHelper::storeFile($picto, $picto->picture, true); $maxOrder = self::where('section_id', $picto->section_id)->max('order'); $picto->order = $maxOrder !== null ? $maxOrder + 1 : 1; }); static::updating(function (self $picto) { $picto->picture = FileStorageHelper::storeFile($picto, $picto->picture, true); if ($picto->isDirty('section_id')) { $maxOrder = self::where('section_id', $picto->section_id)->max('order'); $picto->order = $maxOrder !== null ? $maxOrder + 1 : 1; } }); static::deleting(function (self $picto) { FileStorageHelper::storeFile($picto, $picto->picture, true); }); static::deleted(function (self $picto) { self::where('section_id', $picto->section_id) ->where('order', '>', $picto->order) ->decrement('order'); }); } }