diff --git a/src/Commands/RapydMakeEditCommand.php b/src/Commands/RapydMakeEditCommand.php
index dad4ec2..dc0064c 100644
--- a/src/Commands/RapydMakeEditCommand.php
+++ b/src/Commands/RapydMakeEditCommand.php
@@ -143,9 +143,17 @@ public function handle()
$edit_view = $viewPath.'/'.str_replace('edit', 'view', $component_name).'.blade.php';
$table_view = $viewPath.'/'.str_replace('edit', 'table', $component_name).'.blade.php';
+ $edit_class = $classPath.'/'.$componentName.'.php';
$this->buildLinkToEdit($edit_view, $routename);
$this->buildLinkToAdd($table_view, $routename);
+
+
+ if($routeparent_view) {
+ $this->buildRedirect($edit_class, $routeparent_view, $routeparent_view_parameter);
+ } elseif($routeparent_table) {
+ $this->buildRedirect($edit_class, $routeparent_table);
+ }
$this->comment("component url: $routeuri ".$routename);
}
@@ -175,4 +183,17 @@ protected function buildLinkToAdd($viewpath, $route)
}
}
+
+ protected function buildRedirect($viewpath, $route, $route_parameter = '')
+ {
+ $viewContent = File::get($viewpath);
+ if($viewContent) {
+
+ $precompiler = new RapydTagPrecompiler();
+ $newViewContent = $precompiler($viewContent, ['route' => $route, 'route_parameter'=>$route_parameter, 'ref'=>'redirect']);
+
+ File::put($viewpath, $newViewContent);
+ }
+
+ }
}
diff --git a/src/Commands/Templates/Livewire/DataEdit.stub b/src/Commands/Templates/Livewire/DataEdit.stub
index b8dadab..5699e06 100644
--- a/src/Commands/Templates/Livewire/DataEdit.stub
+++ b/src/Commands/Templates/Livewire/DataEdit.stub
@@ -23,7 +23,7 @@ class {{class}} extends {{baseClassName}}
{
$this->validate();
$this->{{ item }}->save();
- // $this->emit('saved');
+ #redirect
}
public function render()
diff --git a/src/Mechanisms/RapydTagPrecompiler.php b/src/Mechanisms/RapydTagPrecompiler.php
index a4b3efd..1878ce7 100644
--- a/src/Mechanisms/RapydTagPrecompiler.php
+++ b/src/Mechanisms/RapydTagPrecompiler.php
@@ -18,6 +18,10 @@ public function __invoke($value, $params = [])
if ($params['ref'] === 'link-add') {
$value = $this->replaceLinkAddTags($value, '/<\/a>/', $params);
}
+ if ($params['ref'] === 'redirect') {
+ $value = $this->replaceRedirect($value, '/#redirect/', $params);
+ }
+
}
return $value;
@@ -30,7 +34,7 @@ protected function replaceLinkViewTags($value, $pattern, $params = [])
$viewId = str_replace(['{{', '}}'], '', $content);
if(count($params) && isset($params['route'])) {
- return '' . $content . '';
+ return '' . $content . '';
}
return $matches[0];
@@ -43,7 +47,7 @@ protected function replaceLinkEditTags($value, $pattern, $params = [])
$content = $matches[1];
$viewId = str_replace(['{{', '}}'], '', $content);
if(count($params) && isset($params['route'])) {
- return 'Edit';
+ return 'Edit';
}
return $matches[0];
@@ -54,7 +58,18 @@ protected function replaceLinkAddTags($value, $pattern, $params = [])
{
return preg_replace_callback($pattern, function (array $matches) use ($params) {
if(count($params) && isset($params['route'])) {
- return 'Add';
+ return 'Add';
+ }
+ return $matches[0];
+ }, $value);
+ }
+
+ protected function replaceRedirect($value, $pattern, $params = [])
+ {
+ return preg_replace_callback($pattern, function (array $matches) use ($params) {
+ if(count($params) && isset($params['route']) && isset($params['route_parameter'])) {
+ $parameter = str_replace('$','$this->',$params['route_parameter']);
+ return 'return redirect()->to(route_lang("'.$params['route'].'",'.$parameter.' ));';
}
return $matches[0];