Пример #1
0
 public function getAll()
 {
     $diary = '';
     $view = '';
     if (Auth::user()->role == 'admin') {
         $diary = Diary::with(['category', 'tags'])->orderBy('created_at', 'desc')->paginate(40);
         $view = 'admin.diary.alldiary';
     } else {
         $diary = Diary::with(['category', 'tags'])->where('user_id', Auth::user()->id)->orderBy('created_at', 'desc')->paginate(40);
         $view = 'admin.diary.usersalldiary';
     }
     return view($view, ['pageInfo' => ['siteTitle' => 'All Diary', 'pageHeading' => 'All Diary', 'pageHeadingSlogan' => 'I write here what I learn'], 'data' => ['diary' => $diary]]);
 }
Пример #2
0
 public function getRead(Request $req, $id)
 {
     $diary = Diary::with(['comments', 'tags'])->find($id);
     if ($diary->status == 0) {
         if (!Auth::check()) {
             return redirect('diary');
         } elseif (Auth::user()->id != $diary->user_id) {
             return redirect('diary');
         }
     }
     //$comments=Comments::where('diary_id', $id)->get();
     $diary->visits += 1;
     $diary->save();
     return view('site.diary.read', ['pageInfo' => ['pageLogo' => 'diary', 'siteTitle' => $diary->title, 'pageHeading' => 'Diary', 'pageHeadingSlogan' => 'I write here what I learn', 'siteImage' => $diary->featured_image, 'siteContents' => strShorten($diary->note, 200)], 'diary' => $diary, 'comments' => $diary->comments, 'request' => $req]);
 }
Пример #3
0
 public function getSearch(Request $req)
 {
     $query = rawurldecode($req->input('q'));
     $words = explode(' ', $query);
     $skipKeywords = ['in', 'are', 'of', 'at', 'a', 'is', 'to', 'an', 'for', 'and', 'or', 'with'];
     $tags = [];
     $keywords = array_diff($words, $skipKeywords);
     $diary = Diary::with('tags')->where(function ($q) use($keywords) {
         foreach ($keywords as $tag) {
             $q->orWhere('diary.title', 'like', '%' . $tag . '%');
         }
     })->where('diary.status', 1)->orderBy('title', 'asc')->paginate(10);
     if (count($diary) < 1) {
         $tags = Tags::where(function ($q) use($words) {
             foreach ($words as $word) {
                 $q->orWhere('tag_name', 'like', '%' . $word . '%');
             }
         })->get(['tag_name', 'id']);
     }
     return view('site.diary.diary', ['pageInfo' => ['pageLogo' => 'diary', 'siteTitle' => 'Search | ' . $query, 'pageHeading' => 'Search | ' . $query, 'pageHeadingSlogan' => 'Search everything what I write'], 'data' => $diary, 'tags' => $tags]);
 }