FamilyMemberModal.php 2.3 KB
<?php
/**
+-----------------------------------------------------------------------------------------------------------------------
 * grid 列表 modal 类:家庭-成员 modal 类
+-----------------------------------------------------------------------------------------------------------------------
 *
 * PHP version 7
 *
 * @category  App\Admin\Grids\Modal
 * @package   App\Admin\Grids\Modal
 * @author    Richer <yangzi1028@163.com>
 * @date      2022年11月1日16:03:27
 * @copyright 2020-2022 Richer (http://www.Richer.com/)
 * @license   http://www.Richer.com/ License
 * @link      http://www.Richer.com/
 */
namespace App\Admin\Grids\Modal\User;

use App\Admin\Grids\Modal\BaseModal;
use App\Models\User\User;
use App\Transformers\User\UserTransformer;

/**
 * Class FamilyMemberModal
 *
 * @category  App\Admin\Grids\User
 * @package   App\Admin\Grids\User
 * @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 FamilyMemberModal extends BaseModal
{
    public function render($key = null)
    {
        request()->offsetSet('function', 'show');
        $list = User::where('family_id', $key)->orderByRaw("CASE WHEN role='header' THEN 1 END desc")
        ->whereIn('role', array_keys(User::FARMER_ROLE_OPTIONS))
        ->latest()->paginate(request('per_page', 10));
        $paginator = $this->renderPaginator($key, $list, app(UserTransformer::class));
        // 定义需要展示的字段
        $columns = [
            [
                'name'      => __('truename'),
                'field'     => 'name',
            ],
            [
                'name'      => __('mobile'),
                'field'     => 'mobile',
            ],
//            [
//                'name'      => __('house_number'),
//                'field'     => 'house_number',
//            ],
//            [
//                'name'      => __('address'),
//                'field'     => 'address',
//            ],
            [
                'name'      => __('role'),
                'field'     => 'role_show',
            ],
        ];

        $paginator['columns'] = $columns;

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