Detail field display expansion

This feature is used to extend the detail field display, in cases where the built-in display method is not sufficient.

First define the extension class:

  1. <?php
  2. namespace App\Admin\Extensions\Show;
  3. use Dcat\Admin\Show\AbstractField;
  4. class UnSerialize extends AbstractField
  5. {
  6. // Setting this property to false will not escape the HTML code
  7. public $escape = false;
  8. public function render($arg = '')
  9. {
  10. // Returns any content that can be rendered
  11. return unserialize($this->value);
  12. }
  13. }

Then register the extension class in app/Admin/bootstrap.php

  1. use Dcat\Admin\Show\Field;
  2. use App\Admin\Extensions\Show\UnSerialize;
  3. Field::extend('unserialize', UnSerialize::class);

Then use this extension in the controller

  1. $show->column()->unserialize('xxx');

Parameters passed into the unserialize() method are passed sequentially into the UnSerialize::render() method.

Several common attributes can be found in the parent class Dcat\Admin\Show\AbstractField

  1. /**
  2. * Field value.
  3. *
  4. * @var mixed
  5. */
  6. protected $value;
  7. /**
  8. * Current field model.
  9. *
  10. * @var Fluent
  11. */
  12. protected $model;
  13. /**
  14. * If this field show with a border.
  15. *
  16. * @var bool
  17. */
  18. public $border = true;
  19. /**
  20. * If this field show escaped contents.
  21. *
  22. * @var bool
  23. */
  24. public $escape = true;

Where $value and $model are the current field value and the current details of the data, in the render() method can be used to get the data you want.

$border is used to control whether the current display needs a border, $escape is used to set the current display to not HTML escape.