LabelItemModal.php 2.0 KB
<?php
/**
+-----------------------------------------------------------------------------------------------------------------------
 * grid 列表 modal 类:CategoryExample modal 类
+-----------------------------------------------------------------------------------------------------------------------
 *
 * PHP version 7
 *
 * @category  App\Admin\Grids\Modal
 * @package   App\Admin\Grids\Modal
 * @author    Richer <yangzi1028@163.com>
 * @date      2023年4月20日17:24:02
 * @copyright 2020-2022 Richer (http://www.Richer.com/)
 * @license   http://www.Richer.com/ License
 * @link      http://www.Richer.com/
 */
namespace App\Admin\Grids\Modal;

use App\Models\Category\CategoryExample;
use App\Models\LabelItem;
use App\Transformers\CategoryExampleTransformer;
use App\Transformers\User\FamilyTransformer;

/**
 * Class LabelItemModal
 *
 * @category  App\Admin\Grids\Modal
 * @package   App\Admin\Grids\Modal
 * @author    Richer <yangzi1028@163.com>
 * @date      2022年3月15日09:22:19
 * @copyright 2020-2022 Richer (http://www.Richer.com/)
 * @license   http://www.Richer.com/ License
 * @link      http://www.Richer.com/
 */
class LabelItemModal extends BaseModal
{
    public function render($key = null)
    {
        request()->offsetSet('function', 'show');
        $list = LabelItem::where('category_id', $key)->latest()->paginate(request('per_page', 10));
        $paginator = $this->renderPaginator($key, $list, app(CategoryExampleTransformer::class));
        // 定义需要展示的字段
        $columns = [
            [
                'name'      => __('Q'),
                'field'     => 'question',
            ],
            [
                'name'      => __('A'),
                'field'     => 'answer',
            ],
            [
                'name'      => __('created_at'),
                'field'     => 'created_at',
            ],
        ];

        $paginator['columns'] = $columns;

        return view(
            'admin::grid.modal',
            $paginator
        );
    }
}