Change route back to laravel

In my scenario, I go along the following route:

model/{model}/edit

and I'm looking at the route:

model/{model}/duplicate

I make a copy of the model and save it

$duplicate_model = $model->replicate();
$duplicate_model->save();

after that I want to go back to editing the route of the new model, doing something in accordance with this:

return redirect()->back()->with('model' => $duplicate_model);

hoping that it will replace the model identifier with the model of the duplicated model, but this is not so.

I cannot access a specific route, because there are different cases in which you can access a duplicate route.

+4
source share
2 answers

One solution is to obtain permission to resolve the route name from a return URL like this, provided that all possible return routes are called:

$back_route_name = app('router')->getRoutes()->match(app('request')->create(redirect()->back()->getTargetUrl()))->getName();

and then redirect the route by name:

return redirect()->route($back_route_name, ['template' => $duplicate_template]);
+4

"()" . /

//{}/

public function path() { return '/model/'. $this- > id. '/'; }

ThatModelController.php

return redirect ($ dumplicate_model- > path());

, Jeffery Way .

.. slug path() $this- > slug $this- > id

0

Source: https://habr.com/ru/post/1691791/


All Articles