/** * 通过MLSID或第三方网站URL获取房源 * @param Request $request * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|string * @throws \Exception */ public function fetch(Request $request) { $this->validate($request, ['type' => 'required', 'q' => 'required']); //搜索内容 $q = trim($request->q); //判断搜索类型 if ($request->type == 0) { //MLSID $model = Property::where('MLSNumber', $q)->first(); if ($model) { //return view('property._detail', ['record' => $record]); $view = view('property._detail', ['record' => $model]); return response()->json(['model' => $model, 'view' => $view]); } throw new Exception('未找到!'); } else { if ($request->type == 1) { //第三方网站URL $domain = UrlUtil::getMainDomain($q); if (StringUtil::equalsIgnoreCase($domain, 'loopnet.com')) { $model = Util::parseLoopnetProperty($q); $view = view('property._detail', ['model' => $model])->render(); return response()->json(['model' => $model, 'view' => $view]); } else { if (StringUtil::equalsIgnoreCase($domain, 'newhomesource.com')) { $model = Util::parseNewhomesourceProperty($q); $view = view('property._detail', ['model' => $model])->render(); return response()->json(['model' => $model, 'view' => $view]); } else { throw new Exception('您输入的网站URL暂不支持!'); } } } else { throw new Exception('搜索类型错误!'); } } }