admin 发表于 2023-3-12 15:01:15

列表增加调用某个字段

<p>文库读取列表的一个函数</p>

<pre class="brush:html;toolbar:false">public static function listCategoryRecommendLatest($categoryId, $limit = 6)
    {
        return Cache::remember('WenkuDocLatest:' . $categoryId . ':' . $limit, 60, function () use ($categoryId, $limit) {
            $categoryIds = array_merge([$categoryId], WenkuCategoryUtil::childIds($categoryId));
            $records = ModelUtil::model('wenku_doc')
                ->where(['status' => WenkuDocStatus::VERIFY_PASS, 'isDeleted' => false, 'isRecommend' => true,])
                ->whereIn('categoryId', $categoryIds)
                ->limit($limit)
                ->orderBy('id', 'desc')
                ->get(['hash', 'title', 'ext', 'cover', 'pagePreviews', 'memberUserId'])->toArray();
            ModelUtil::decodeRecordsJson($records, ['pagePreviews']);
            foreach ($records as $k => $v) {
                $records[$k]['cover'] = WenkuDocUtil::cover($v);
                unset($records[$k]['pagePreviews']);
            }
            MemberUtil::mergeMemberUserBasics($records);
            return $records;
        });
    }</pre>

<p>想读取页数,日期,分类id等字段,在get这里加了字段</p>

<pre class="brush:html;toolbar:false">->get(['hash', 'title', 'ext', 'cover', 'pagePreviews', 'memberUserId', 'created_at', 'categoryId', 'pageCount'])->toArray();</pre>

<p><br></p>

<p>在视图页面调用<br></p>

<pre class="brush:html;toolbar:false"> {{$record['pageCount']}} , {{$record['created_at']}}, {{$record['categoryId']}}</pre>

<p>这样会出错500,应该怎么修改,是不是还要修改哪里<br></p>
页: [1]
查看完整版本: 列表增加调用某个字段