|
@@ -558,11 +558,10 @@ class Form implements Renderable
|
|
|
return $response;
|
|
|
}
|
|
|
|
|
|
- if ($response = $this->ajaxResponse(trans('admin.save_succeeded'), $this->getRedirectUrl($id, $redirectTo))) {
|
|
|
- return $response;
|
|
|
- }
|
|
|
-
|
|
|
- return $this->redirectAfterStore($id, $redirectTo);
|
|
|
+ return $this->redirect(
|
|
|
+ $this->getRedirectUrl($id, $redirectTo),
|
|
|
+ trans('admin.save_succeeded')
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -712,38 +711,42 @@ class Form implements Renderable
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
- if ($response = $this->ajaxResponse(trans('admin.update_succeeded'), $this->getRedirectUrl($id, $redirectTo))) {
|
|
|
- return $response;
|
|
|
- }
|
|
|
-
|
|
|
- return $this->redirectAfterUpdate($id, $redirectTo);
|
|
|
+ return $this->redirect(
|
|
|
+ $this->getRedirectUrl($id, $redirectTo),
|
|
|
+ trans('admin.update_succeeded')
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Get RedirectResponse after store.
|
|
|
+ * Get redirect response.
|
|
|
*
|
|
|
- * @param $id
|
|
|
- * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
|
|
+ * @param string $url
|
|
|
+ * @param array|string $options
|
|
|
+ * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
|
|
*/
|
|
|
- protected function redirectAfterStore($id, $redirectTo)
|
|
|
+ public function redirect(?string $url, $options = null)
|
|
|
{
|
|
|
- admin_alert(trans('admin.save_succeeded'));
|
|
|
+ if (is_string($options)) {
|
|
|
+ $message = $options;
|
|
|
+ $options = [];
|
|
|
+ } else {
|
|
|
+ $message = $options['message'] ?? trans('admin.save_succeeded');
|
|
|
+ }
|
|
|
|
|
|
- return redirect($this->getRedirectUrl($id, $redirectTo));
|
|
|
- }
|
|
|
+ $status = (bool) ($options['status'] ?? true);
|
|
|
|
|
|
- /**
|
|
|
- * Get RedirectResponse after update.
|
|
|
- *
|
|
|
- * @param mixed $key
|
|
|
- *
|
|
|
- * @return \Illuminate\Http\RedirectResponse
|
|
|
- */
|
|
|
- protected function redirectAfterUpdate($key, $redirectTo)
|
|
|
- {
|
|
|
- admin_alert(trans('admin.save_succeeded'));
|
|
|
+ // 判断是否是ajax请求
|
|
|
+ if ($response = $this->ajaxResponse($message, $url, $status)) {
|
|
|
+ return $response;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 非ajax请求
|
|
|
+ $status = $options['status'] ?? 200;
|
|
|
+
|
|
|
+ admin_alert($message);
|
|
|
+
|
|
|
+ return redirect($url, $status);
|
|
|
|
|
|
- return redirect($this->getRedirectUrl($key, $redirectTo));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -1422,6 +1425,19 @@ class Form implements Renderable
|
|
|
return Arr::set($this->inputs, $key, $value);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Get or set input data.
|
|
|
+ *
|
|
|
+ * @param string|array $keys
|
|
|
+ * @param null $value
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function forgetInput($keys)
|
|
|
+ {
|
|
|
+ Arr::forget($this->inputs, $keys);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @param int $width
|
|
|
* @param Closure $callback
|