Skip to content

Commit

Permalink
修复表单继续编辑功能跳转异常问题
Browse files Browse the repository at this point in the history
  • Loading branch information
jqhph committed Nov 29, 2020
1 parent ea67920 commit 67f411f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
12 changes: 8 additions & 4 deletions src/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public function __construct($repository = null, ?Closure $callback = null, Reque
{
$this->repository = $repository ? Admin::repository($repository) : null;
$this->callback = $callback;
$this->request = $request ?: request();
$this->request = clone ($request ?: request());
$this->builder = new Builder($this);
$this->isSoftDeletes = $repository ? $this->repository->isSoftDeletes() : false;

Expand Down Expand Up @@ -642,9 +642,11 @@ public function store(?array $data = null, $redirectTo = null)
);
}

$url = $this->getRedirectUrl($id, $redirectTo);

return $this->sendResponse(
$this->response()
->redirect($this->getRedirectUrl($id, $redirectTo))
->redirectIf($url !== false, $url)
->success(trans('admin.save_succeeded'))
);
} catch (\Throwable $e) {
Expand Down Expand Up @@ -814,10 +816,12 @@ public function update(
);
}

$url = $this->getRedirectUrl($id, $redirectTo);

return $this->sendResponse(
$this->response()
->success(trans('admin.update_succeeded'))
->redirect($this->getRedirectUrl($id, $redirectTo))
->redirectIf($url !== false, $url)
);
} catch (\Throwable $e) {
$response = $this->handleException($e);
Expand Down Expand Up @@ -932,7 +936,7 @@ public function getRedirectUrl($key, $redirectTo = null)
if ($this->request->get('after-save') == 1) {
// continue editing
if ($this->builder->isEditing()) {
return;
return false;
}

return rtrim($resourcesPath, '/')."/{$key}/edit";
Expand Down
5 changes: 1 addition & 4 deletions src/Form/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -578,10 +578,7 @@ public function getElementId()
public function hasFile()
{
foreach ($this->fields() as $field) {
if (
$field instanceof UploadField
|| $field instanceof Form\Field\BootstrapFile
) {
if ($field instanceof UploadField) {
return true;
}
}
Expand Down

0 comments on commit 67f411f

Please sign in to comment.