Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

orm 多库链接的情况无法在模型中通过$connection指定连接

未关闭
#105 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
mysql, php
领域
databases

调研方向

Start at the selectInput(Request $request) method shown in the issue and trace how the model and database connection are selected before the table description query runs. Verify the multi-database case where a model specifies $connection, and consider the issue complete when the query uses that connection instead of assuming the mysql configuration.

由索引模型根据 Issue 内容生成。

描述

orm 多库链接的情况无法在模型中通过$connection指定连接
指定第二个库时,查询列表会报错 说第一个库不存在某表
排查到原因是
` protected function selectInput(Request $request): array
{
$field = $request->get('field');
$order = $request->get('order', 'asc');
$format = $request->get('format', 'normal');
$limit = (int)$request->get('limit', $format === 'tree' ? 1000 : 10);
$limit = $limit <= 0 ? 10 : $limit;
$order = $order === 'asc' ? 'asc' : 'desc';
$where = $request->get();
$page = (int)$request->get('page');
$page = $page > 0 ? $page : 1;
$table = config('plugin.admin.database.connections.mysql.prefix') . $this->model->getTable();

    $allow_column = Util::db()->select("desc `$table`");
    if (!$allow_column) {
        throw new BusinessException('表不存在');
    }
    $allow_column = array_column($allow_column, 'Field', 'Field');
    if (!in_array($field, $allow_column)) {
        $field = null;
    }
    foreach ($where as $column => $value) {
        if (
            $value === '' || !isset($allow_column[$column]) ||
            is_array($value) && (empty($value) || !in_array($value[0], ['null', 'not null']) && !isset($value[1]))
        ) {
            unset($where[$column]);
        }
    }
    // 按照数据限制字段返回数据
    if (!Auth::isSuperAdmin()) {
        if ($this->dataLimit === 'personal') {
            $where[$this->dataLimitField] = admin_id();
        } elseif ($this->dataLimit === 'auth') {
            $primary_key = $this->model->getKeyName();
            if (!Auth::isSuperAdmin() && (!isset($where[$primary_key]) || $this->dataLimitField != $primary_key)) {
                $where[$this->dataLimitField] = ['in', Auth::getScopeAdminIds(true)];
            }
        }
    }
    return [$where, $format, $limit, $field, $order, $page];
}`

中config('plugin.admin.database.connections.mysql.prefix') 写死了这个mysql

主要语言
JavaScript
星标
378
派生
48
平均合并
20 小时 9 分钟
30 天内合并 PR
2

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

webman-php/admin 的其他 Issue

查看 webman-php/admin 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。