From 10673c6be9265fe48fe8c8bb30f04a4dab0a4bbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Wed, 11 Aug 2021 10:10:18 +0300 Subject: [PATCH] Document transaction listener add isAjax control.. --- .../Document/CreateDocumentTransaction.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/app/Listeners/Document/CreateDocumentTransaction.php b/app/Listeners/Document/CreateDocumentTransaction.php index cd5c16245..76c4535f7 100644 --- a/app/Listeners/Document/CreateDocumentTransaction.php +++ b/app/Listeners/Document/CreateDocumentTransaction.php @@ -36,16 +36,30 @@ class CreateDocumentTransaction if (empty($user) || $signed) { flash($message)->error()->important(); - redirect()->route("signed.$type.show", $document->id)->send(); + return $this->getResponse('signed.' . $type . '.show', $document, $message); } if ($user->can('read-client-portal')) { flash($message)->error()->important(); - redirect()->route("portal.$type.show", $document->id)->send(); + return $this->getResponse('portal.' . $type . '.show', $document, $message); } throw new \Exception($message); } } + + protected function getResponse($path, $document, $message) + { + if (request()->expectsJson()) { + return response()->json([ + 'success' => false, + 'errors' => true, + 'message' => $message, + 'redirect' => route($path, $document->id) + ]); + } + + return redirect()->route($path, $document->id); + } }