public function show($url) { $travel = Travel::where('url', $url)->first(); if ($travel) { return view('travels.show', ['travel' => $travel]); } return view('errors.404'); }
/** * 游记详情 * @param $slug string * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function travelDetail($slug) { $data = Cache::remember("travel.detail.{$slug}", self::CACHE_TIME, function () use($slug) { $destinationList = $this->destination->getList(12); $detail = $this->travel->where('slug', $slug)->firstOrFail(); $detail->content = Markdown::convertToHtml($detail->content); $destinationInfo = $detail->destination; $travelList = $this->travel->where('destination_id', $destinationInfo['id'])->where('id', '<>', $detail->id)->latest('begin_date')->take(5)->get(); //10篇同目的地的最新游记 $travelList = !$travelList->isEmpty() ? $travelList : ''; return ['destinationList' => $destinationList, 'destinationInfo' => $destinationInfo, 'detail' => $detail, 'travelList' => $travelList]; }); $destinationList = $data['destinationList']; $destinationInfo = $data['destinationInfo']; $detail = $data['detail']; $travelList = $data['travelList']; $seoSuffix = "_{$destinationInfo->destination}游记_tanteng.me"; return view('travel.detail', compact('detail', 'destinationList', 'destinationInfo', 'travelList', 'seoSuffix')); }