protected function sidebarCategory() { if (!Cache::has('_tags')) { $tags = Tagged::join('tags', 'tagged.tag_id', '=', 'tags.id')->select('tags.id', DB::raw('count(tag_id) as total_tags'), 'tags.tag_name')->groupBy('tagged.tag_id')->take(20)->get(); Cache::put('_tags', $tags, 60); } if (!Cache::has('_category')) { $category = Category::get(); Cache::put('_category', $category, 60); } if (!Cache::has('_recent')) { $recent = Diary::where('status', 1)->orderBy('created_at', 'desc')->take(5)->get(['title', 'id']); Cache::put('_recent', $recent, 60); } view()->composer('site.partials.sidebar', function ($view) { $view->with('navData', ['category' => Cache::get('_category'), 'recents' => Cache::get('_recent'), 'tags' => Cache::get('_tags')]); }); }
public function getIndex() { $diary = Diary::where('status', 1)->where('category_id', '!=', 7)->with(['tags'])->orderBy('created_at', 'desc')->paginate(10); return view('site.diary.diary', ['pageInfo' => ['pageLogo' => 'diary', 'siteTitle' => 'Diary', 'pageHeading' => 'Diary', 'pageHeadingSlogan' => 'I write here what I learn'], 'data' => $diary]); }
public function getDelete($id) { if (Auth::user()->role == 'admin') { if (Diary::find($id)->delete()) { return redirect()->back()->with('msg', 'deleted'); } } if (Diary::where('user_id', Auth::user()->id)->where('id', $id)->exists()) { if (Diary::find($id)->delete()) { return redirect()->back()->with('msg', 'deleted'); } } return redirect()->back(); }