| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- /**
- * 通用详情返回封装.
- *
- * @author nj
- * @date 2021-01-24 02:20:30
- */
- namespace Modules\ManageApi\Responses;
- use Illuminate\Contracts\Support\Arrayable;
- use Illuminate\Contracts\Support\Responsable;
- class CommonDetailResponse implements Responsable
- {
- /**
- * 录入的数据.
- *
- * @var mixed
- */
- private $data = null;
- /**
- * 附加条件参数.
- *
- * @var array
- */
- private $params = [];
- public function __construct($data = null, $params = [])
- {
- $this->data = $data;
- $this->params = $params;
- }
- public function toResponse(
- $request = null
- )
- {
- if (empty($this->data)) {
- return json_fail(trans('common.err_resource_not_found'));
- }
- if (is_array($this->data)) {
- $result = $this->data;
- } else {
- $result = $this->data->toArray();
- }
- return json_success($result);
- }
- }
|