Data detail actions

Run command

  1. php artisan admin:action

Then enter 5.

  1. Which type of action would you like to make?:
  2. [0] default
  3. [1] grid-batch
  4. [2] grid-row
  5. [3] grid-tool
  6. [4] form-tool
  7. [5] show-tool
  8. [6] tree-tool
  9. > 5 # Enter 5

Next, type in the name of the Action class in PascalCase style.

  1. Please enter a name of action class:
  2. > Copy

The default namespace is App\Admin\ActionsShow\, just use the default one here.

  1. Please enter the namespace of action class [App\Admin\Actions\Show]:
  2. >

The final file is as follows

  1. <?php
  2. namespace App\Admin\Actions\Show;
  3. use Dcat\Admin\Actions\Response;
  4. use Dcat\Admin\Show\AbstractTool;
  5. use Dcat\Admin\Traits\HasPermissions;
  6. use Illuminate\Contracts\Auth\Authenticatable;
  7. use Illuminate\Database\Eloquent\Model;
  8. use Illuminate\Http\Request;
  9. class Copy extends AbstractTool
  10. {
  11. /**
  12. * Button Title
  13. *
  14. * @return string
  15. */
  16. protected $title = 'Title';
  17. /**
  18. * Process the request, if you don't need the interface to process it, simply delete this method.
  19. *
  20. * @param Request $request
  21. *
  22. * @return Response
  23. */
  24. public function handle(Request $request)
  25. {
  26. // Get Primary Key
  27. $key = $this->getKey();
  28. return $this->response()
  29. ->success('Processed successfully.')
  30. ->redirect('/');
  31. }
  32. /**
  33. * If it's just a tag jump, then just return the jump link here
  34. *
  35. * @return string|void
  36. */
  37. protected function href()
  38. {
  39. // Get Primary Key
  40. $key = $this->getKey();
  41. // Get other fields of the current page
  42. $username = $this->parent->model()->username;
  43. // return admin_url('auth/users');
  44. }
  45. // If you want to customize the HTML of the action button, you can rewrite this method
  46. public function html()
  47. {
  48. return parent::html();
  49. }
  50. /**
  51. * Confirm the pop-up message, and delete this method if you don't need it.
  52. *
  53. * @return string|array|void
  54. */
  55. public function confirm()
  56. {
  57. // return ['Confirm?', 'contents'];
  58. }
  59. /**
  60. * Check Permissions. If you do not need this method can be deleted.
  61. *
  62. * @param Model|Authenticatable|HasPermissions|null $user
  63. *
  64. * @return bool
  65. */
  66. protected function authorize($user): bool
  67. {
  68. return true;
  69. }
  70. /**
  71. * Returns the parameters of the requesting interface, or removes this method if not required.
  72. *
  73. * @return array
  74. */
  75. protected function parameters()
  76. {
  77. return [];
  78. }
  79. }

Usage

  1. $show->tools(function (Show\Tools $tools) {
  2. $tools->append(new Copy());
  3. });