PermissionRoleDetailResponse.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * 角色详情.
  4. *
  5. * @author nj <nj@gmail.com>
  6. * @date 2020-01-24 02:23:36
  7. */
  8. declare(strict_types=1);
  9. namespace Modules\Manage\Responses;
  10. use App\Contracts\Responsable;
  11. class PermissionRoleDetailResponse implements Responsable
  12. {
  13. /**
  14. * 录入的数据.
  15. *
  16. * @var mixed
  17. */
  18. private $data = null;
  19. /**
  20. * 附加条件参数.
  21. *
  22. * @var array
  23. */
  24. private $params = [];
  25. public function __construct($data = null, $params = [])
  26. {
  27. $this->data = $data;
  28. $this->params = $params;
  29. }
  30. public function toResponse(
  31. $request = null
  32. ) {
  33. if (empty($this->data)) {
  34. return json_fail(trans('common.err_resource_not_found'));
  35. }
  36. $result = $this->data->toArray();
  37. $strPermissions = $result['permissions'];
  38. $arrPermissions = [];
  39. if (!empty($strPermissions)) {
  40. $arrPermissions = explode(',', $strPermissions);
  41. }
  42. $result['permissions'] = $arrPermissions;
  43. return json_success($result);
  44. }
  45. }