File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -59,6 +59,20 @@ public function saving($model)
5959 $ this ->clearCached ();
6060 }
6161
62+ /**
63+ * @param Content&Model $model
64+ * @return void
65+ */
66+ public function saved ($ model )
67+ {
68+ if ($ model ->isDirty (['is_default ' ])) {
69+ // Update the route if default content is changed -> default route should be updated
70+ $ provider = ContentSegmentFactory::create ();
71+ $ this ->updateCurrentRouteInDefaultPattern ($ model , $ provider );
72+ }
73+
74+ }
75+
6276 /**
6377 * @param Content&Model $model
6478 * @return void
@@ -155,6 +169,29 @@ protected function createDefaultRoute($model, $provider)
155169 ));
156170 }
157171
172+ /**
173+ * @param Content & Model $model
174+ * @param SegmentProviderInterface $provider
175+ */
176+ protected function updateCurrentRouteInDefaultPattern ($ model , $ provider )
177+ {
178+ if (! $ model ->isWebPage ()) {
179+ return ;
180+ }
181+
182+ $ uri = $ provider ->getSegment ($ model );
183+
184+ $ currentRoutes = collect ($ model ->routes ()->where ('is_default_pattern ' , true )->get ())
185+ ->map (fn (Model $ model ) => $ model ->toArray ())
186+ ->map (function (array $ data ) use ($ uri ) {
187+ $ data ['uri ' ] = $ uri ;
188+ return $ data ;
189+ })
190+ ->all ();
191+
192+ event (new UpsertRoute ($ model ->withoutRelations (), $ currentRoutes ));
193+ }
194+
158195 /**
159196 * @param \SolutionForest\InspireCms\Models\Contracts\Content|\Illuminate\Database\Eloquent\Model $original
160197 * @return \Illuminate\Database\Eloquent\Collection
You can’t perform that action at this time.
0 commit comments