/** * On update, update children uris * * @param Page $model * @return void */ public function updating(Page $model) { if ($model->isDirty('parent_id')) { foreach (Config::get('app.locales') as $locale) { $model->translate($locale)->uri = ''; } } }
/** * Recursive method for emptying children’s uri * UriObserver will rebuild uris. * * @param Page $page * * @return void */ public function resetChildrenUri(Page $page) { foreach ($page->children as $childPage) { foreach (config('translatable.locales') as $locale) { if (is_null($page->translate($locale)->uri)) { $childPage->translate($locale)->uri = null; } else { $childPage->translate($locale)->uri = ''; } } $childPage->save(); $this->resetChildrenUri($childPage); } }