Model tree action

Toolbar

Run command

  1. php artisan admin:action

Then enter 7.

  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-row
  9. [7] tree-tool
  10. > 7 # Enter 7

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\Actions\Tree, just use the default one here.

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

The final file is as follows

  1. <?php
  2. namespace App\Admin\Actions\Tree;
  3. use Dcat\Admin\Actions\Response;
  4. use Dcat\Admin\Tree\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. return $this->response()
  27. ->success('Processed successfully.')
  28. ->redirect('/');
  29. }
  30. /**
  31. * If it's just a tag jump, then just return the jump link here
  32. *
  33. * @return string|void
  34. */
  35. protected function href()
  36. {
  37. // return admin_url('auth/users');
  38. }
  39. // If you want to customize the HTML of the action button, you can rewrite this method
  40. public function html()
  41. {
  42. return parent::html();
  43. }
  44. /**
  45. * Confirm the pop-up message, and delete this method if you don't need it.
  46. *
  47. * @return string|array|void
  48. */
  49. public function confirm()
  50. {
  51. // return ['Confirm?', 'contents'];
  52. }
  53. /**
  54. * Check Permissions. If you do not need this method can be deleted.
  55. *
  56. * @param Model|Authenticatable|HasPermissions|null $user
  57. *
  58. * @return bool
  59. */
  60. protected function authorize($user): bool
  61. {
  62. return true;
  63. }
  64. /**
  65. * Returns the parameters of the requesting interface, or removes this method if not required.
  66. *
  67. * @return array
  68. */
  69. protected function parameters()
  70. {
  71. return [];
  72. }
  73. }

Usage

  1. $tree->tools(function (Tree\Tools $tools) {
  2. $tools->add(new Copy());
  3. });

Line operations

Run Command

  1. php artisan admin:action

Then enter 6

  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-row
  9. [7] tree-tool
  10. > 6 # Enter 6

Next, enter the name of the Action class, here you need to enter the letters of the Big Hump style.

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

After the class name is entered, the following message will appear for the developer to enter the namespace of the class, the default namespace is App\Admin\Actions\Tree.

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

The final file is generated as follows

  1. <?php
  2. namespace App\Admin\Actions\Tree;
  3. use Dcat\Admin\Tree\RowAction;
  4. use Dcat\Admin\Actions\Response;
  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 RowAction
  10. {
  11. /**
  12. * @return string
  13. */
  14. protected $title = 'Title';
  15. /**
  16. * Process the request, if you don't need the interface to process it, simply delete this method.
  17. *
  18. * @param Request $request
  19. *
  20. * @return Response
  21. */
  22. public function handle(Request $request)
  23. {
  24. // Get the primary key
  25. $key = $this->getKey();
  26. return $this->response()
  27. ->success('Processed successfully.')
  28. ->redirect('/');
  29. }
  30. /**
  31. * Returns the jump address, which can be deleted if not needed.
  32. *
  33. * @return string|void
  34. */
  35. protected function href()
  36. {
  37. // return admin_url('auth/users/'.$this->getKey());
  38. }
  39. /**
  40. * Acknowledge pop-up messages and delete them if they are not needed.
  41. *
  42. * @return string|array|void
  43. */
  44. public function confirm()
  45. {
  46. // return ['Confirm?', 'contents'];
  47. }
  48. /**
  49. * Permissions are checked here and can be deleted if not needed.
  50. *
  51. * @param Model|Authenticatable|HasPermissions|null $user
  52. *
  53. * @return bool
  54. */
  55. protected function authorize($user): bool
  56. {
  57. return true;
  58. }
  59. }

Usage

  1. $tree->actions(new Copy());