Skip to content

Commit

Permalink
数据仓库 store/update/delete 方法允许返回 JsonResponse 对象
Browse files Browse the repository at this point in the history
  • Loading branch information
jqhph committed Mar 5, 2021
1 parent 993a84d commit 8188788
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/Contracts/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function detail(Show $show);
*
* @param Form $form
*
* @return mixed
* @return int|bool|\Dcat\Admin\Http\JsonResponse
*/
public function store(Form $form);

Expand All @@ -95,7 +95,7 @@ public function updating(Form $form);
*
* @param Form $form
*
* @return bool
* @return bool|\Dcat\Admin\Http\JsonResponse
*/
public function update(Form $form);

Expand All @@ -105,7 +105,7 @@ public function update(Form $form);
* @param Form $form
* @param array $deletingData
*
* @return mixed
* @return mixed|\Dcat\Admin\Http\JsonResponse
*/
public function delete(Form $form, array $deletingData);

Expand Down
16 changes: 16 additions & 0 deletions src/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Dcat\Admin\Form\Condition;
use Dcat\Admin\Form\Field;
use Dcat\Admin\Form\NestedForm;
use Dcat\Admin\Http\JsonResponse;
use Dcat\Admin\Support\Helper;
use Dcat\Admin\Traits\HasBuilderEvents;
use Dcat\Admin\Traits\HasFormResponse;
Expand Down Expand Up @@ -568,6 +569,11 @@ public function destroy($id)

$result = $this->repository->delete($this, $data);

// 返回 JsonResponse 对象,直接中断后续逻辑
if ($result instanceof JsonResponse) {
return $this->sendResponse($result);
}

if ($response = $this->callDeleted($result)) {
return $this->sendResponse($response);
}
Expand Down Expand Up @@ -628,6 +634,11 @@ public function store(?array $data = null, $redirectTo = null)

$id = $this->repository->store($this);

// 返回 JsonResponse 对象,直接中断后续逻辑
if ($id instanceof JsonResponse) {
return $this->sendResponse($id);
}

$this->builder->setResourceId($id);

if (($response = $this->callSaved($id))) {
Expand Down Expand Up @@ -804,6 +815,11 @@ public function update(

$updated = $this->repository->update($this);

// 返回 JsonResponse 对象,直接中断后续逻辑
if ($updated instanceof JsonResponse) {
return $this->sendResponse($updated);
}

if ($response = $this->callSaved($updated)) {
return $this->sendResponse($response);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Repositories/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function detail(Show $show)
*
* @param Form $form
*
* @return mixed
* @return int|bool|\Dcat\Admin\Http\JsonResponse
*/
public function store(Form $form)
{
Expand All @@ -136,7 +136,7 @@ public function store(Form $form)
*
* @param Form $form
*
* @return array
* @return array|\Illuminate\Contracts\Support\Arrayable
*/
public function updating(Form $form)
{
Expand All @@ -148,7 +148,7 @@ public function updating(Form $form)
*
* @param Form $form
*
* @return bool
* @return bool|\Dcat\Admin\Http\JsonResponse
*/
public function update(Form $form)
{
Expand All @@ -161,7 +161,7 @@ public function update(Form $form)
* @param Form $form
* @param array $deletingData
*
* @return mixed
* @return bool|int|\Dcat\Admin\Http\JsonResponse
*/
public function delete(Form $form, array $deletingData)
{
Expand Down

0 comments on commit 8188788

Please sign in to comment.