LazyWidget.php 873 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace Dcat\Admin\Traits;
  3. use Dcat\Admin\Admin;
  4. /**
  5. * Trait LazyWidget.
  6. *
  7. * @package Dcat\Admin\Traits
  8. *
  9. * @property string $translation
  10. */
  11. trait LazyWidget
  12. {
  13. protected $payload = [];
  14. public function payload(array $payload)
  15. {
  16. $this->payload = array_merge($this->payload, $payload);
  17. return $this;
  18. }
  19. public function translation()
  20. {
  21. return empty($this->translation) ? Admin::translator()->getPath() : $this->translation;
  22. }
  23. public function getUrl()
  24. {
  25. $data = array_merge($this->payload, [
  26. 'renderable' => $this->getRenderableName(),
  27. '_trans_' => $this->translation(),
  28. ]);
  29. return route(admin_api_route_name('render'), $data);
  30. }
  31. protected function getRenderableName()
  32. {
  33. return str_replace('\\', '_', static::class);
  34. }
  35. }