RowAction.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace Dcat\Admin\Tree;
  3. use Dcat\Admin\Actions\Action;
  4. class RowAction extends Action
  5. {
  6. /**
  7. * @var \Dcat\Admin\Tree\Actions;
  8. */
  9. protected $actions;
  10. /**
  11. * @var \Illuminate\Database\Eloquent\Model
  12. */
  13. protected $row;
  14. /**
  15. * 获取主键值.
  16. *
  17. * @return array|mixed|string
  18. */
  19. public function getKey()
  20. {
  21. if ($key = parent::getKey()) {
  22. return $key;
  23. }
  24. return $this->row->{$this->actions->parent()->getKeyName()};
  25. }
  26. /**
  27. * 获取行数据.
  28. *
  29. * @return \Illuminate\Database\Eloquent\Model
  30. */
  31. public function getRow()
  32. {
  33. return $this->row;
  34. }
  35. /**
  36. * 获取资源路径.
  37. *
  38. * @return string
  39. */
  40. public function resource()
  41. {
  42. return $this->actions->parent()->resource();
  43. }
  44. public function getActions()
  45. {
  46. return $this->actions;
  47. }
  48. public function setParent(Actions $actions)
  49. {
  50. $this->actions = $actions;
  51. }
  52. public function setRow($row)
  53. {
  54. $this->row = $row;
  55. }
  56. }