RowAction.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace Dcat\Admin\Grid;
  3. use Illuminate\Support\Fluent;
  4. abstract class RowAction extends GridAction
  5. {
  6. /**
  7. * @var Fluent
  8. */
  9. protected $row;
  10. /**
  11. * @var Column
  12. */
  13. protected $column;
  14. /**
  15. * @var string
  16. */
  17. public $selectorPrefix = '.grid-row-action-';
  18. /**
  19. * Get primary key value of current row.
  20. *
  21. * @return mixed
  22. */
  23. public function getKey()
  24. {
  25. if ($this->row) {
  26. return $this->row->get($this->parent->getKeyName());
  27. }
  28. return parent::getKey();
  29. }
  30. /**
  31. * Set row model.
  32. *
  33. * @param mixed $key
  34. *
  35. * @return \Illuminate\Database\Eloquent\Model|mixed
  36. */
  37. public function row($key = null)
  38. {
  39. if (func_num_args() == 0) {
  40. return $this->row;
  41. }
  42. return $this->row->{$key};
  43. }
  44. /**
  45. * Set row model.
  46. *
  47. * @param Fluent $row
  48. *
  49. * @return $this
  50. */
  51. public function setRow($row)
  52. {
  53. $this->row = $row;
  54. return $this;
  55. }
  56. public function getRow()
  57. {
  58. return $this->row;
  59. }
  60. /**
  61. * @param Column $column
  62. *
  63. * @return $this
  64. */
  65. public function setColumn(Column $column)
  66. {
  67. $this->column = $column;
  68. return $this;
  69. }
  70. }