CatchAdmin使用小技巧

字符串转数组

引用Utils

use catcher\Utils;

使用方法

Utils::stringToArrayBy($exe_date,'|')
//stringToArrayBy(string  $string, $dep = ',')---参数1字符串,参数2分隔符

关联多张表查询

功能说明

该功能支持多表查询、联合同张表不同字段以及其中副表与其他表联合查询

使用catchLeftJoin()

$list = $this->withoutField(['updated_at'], true)
            ->catchSearch()
            ->catchLeftJoin([Cate::class,'nurse_project_cate'], 'id', 'nurse_project_cate', ['textvalue nurse_project_cate'])
            ->catchLeftJoin([Cate::class, 'cost_method'], 'id', 'cost_method', ['textvalue cost_method'])
            ->catchLeftJoin([NursePlan::class,'nurse_plan'], 'nurse_project_id', 'id',['nurse_level_id,exe_rate_id,nurse_project_id,exe_date,exe_time'])
            ->catchLeftJoin([Cate::class,'exe_rate','nurse_plan'], 'id', 'exe_rate_id',['textvalue exe_rate'])
            ->order($this->aliasField('id'), 'desc')
            ->paginate();

修改catchJoin方法

    public function catchJoin($model, string $joinField, string $currentJoinField, array $field = [], string $type = 'INNER', array $bind = []): CatchQuery
    {
        $tableAlias = null;  //主表别名
        $otherTableAlias = null; //副表别名,其中副表跟其他表联合查询
        if (is_string($model)) {
            $table = app($model)->getTable();
            $tableAlias = $table;
        } else {
            if (count($model) == 3) {
                list($model, $tableAlias, $otherTable) = $model;
            } else {
                list($model, $tableAlias) = $model;
            }
            $table = sprintf('%s %s', app($model)->getTable(), $tableAlias);
        }
        $otherTable = empty($otherTable) ? $this->getAlias() : $otherTable;
        // 合并字段
        $this->options['field'] = array_merge($this->options['field'] ?? [], array_map(function ($value) use ($tableAlias) {
            return $tableAlias . '.' . $value;
        }, $field));
        return $this->join($table, sprintf('%s.%s=%s.%s', $tableAlias, $joinField, $otherTable, $currentJoinField), $type, $bind);
    }

结合搜索多条件查询

model文件下创建search文件夹,并且创建相对于的search文件

命名规范:module名+Search 在这里插入图片描述

使用search

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值