validator; } /** * 构造 CrudUtil 查询配置 */ protected function buildQueryConfig(Request $request, string $scene = 'default'): array { $p = $request->all(); $config = []; $config['model'] = $this->modelClass; switch ($scene) { case 'default': $config['where']['status'] = 1; $config['order']['id'] = 'desc'; break; case 'index': $config['where']['status'] = 1; $config['order']['id'] = 'desc'; // 帖子 if (isset($p['post_id']) && !empty($p['post_id'])) { $config['where']['post_id'] = $p['post_id']; } // 用户 if (isset($p['user_id']) && !empty($p['user_id'])) { $config['where']['user_id'] = $p['user_id']; } // 只查询根评论 if (isset($p['parent_id']) && $p['parent_id'] == 0) { $config['where']['parent_id'] = 0; } // 根评论ID if (isset($p['parent_id']) && !empty($p['parent_id'])) { $config['where']['root_id'] = $p['parent_id']; } // 根评论ID if (isset($p['status']) && !empty($p['status'])) { $config['where']['status'] = $p['status']; } break; case 'show': $config['where']['id'] = $p['id']; $config['where']['status'] = 1; break; case 'store': break; case 'update': $config['where']['id'] = $p['id']; break; case 'destroy': $config['where']['id'] = $p['id']; break; } return $config; } /** * 添加前置处理 */ public function beforeServiceStore($data, Request $request) { $data['user_id'] = $request->user->uid;; $data['root_id'] = 0; if(!empty($data['parent_id'])){ $data['root_id'] = PostComment::where('id', $data['parent_id'])->value('root_id'); } return $data; } }