Пример #1
0
 /**
  * Display the specified resource.
  *
  * @param int $id
  *
  * @return \Illuminate\Http\Response
  */
 public function show($society, $author = "all", $subject = "all")
 {
     $data['author'] = $author;
     if ($author != "all") {
         $filterindiv = Individual::where('slug', '=', $author)->first();
         $filter = "Showing posts by " . $filterindiv->firstname . " " . $filterindiv->surname;
         if ($subject != "all") {
             $filter = $filter . " tagged " . $subject;
         }
     } elseif ($subject != "all") {
         $filter = "Showing posts tagged " . $subject;
     } else {
         $filter = "Showing all posts";
     }
     $data['filter'] = $filter;
     $data['subjects'] = Subject::has('blog')->orderBy('subject')->get();
     $data['bloggers'] = Individual::has('blog')->orderBy('surname')->orderBy('firstname')->get();
     $data['soc'] = $society;
     $data['pagetitle'] = $society . " Blog";
     $data['society'] = Society::where('society', '=', $society)->first();
     $blogs = Blog::with('individual')->orderBy('created_at', 'desc')->get();
     $blogids = array();
     if (count($blogs)) {
         $first = true;
         foreach ($blogs as $blog) {
             $societies = explode(',', $blog->societies);
             if (in_array($data['society']->id, $societies)) {
                 $subjs = array();
                 $thissubjs = $blog->subject;
                 foreach ($thissubjs as $thissub) {
                     $subjs[] = $thissub->subject;
                 }
                 if ($subject == "all" or in_array($subject, $subjs)) {
                     if ($author == "all" or $author == $blog->individual->slug) {
                         $blogids[] = $blog->id;
                     }
                 }
             }
         }
     }
     $data['blogs'] = Blog::with('individual')->wherein('id', $blogids)->orderBy('created_at', 'desc')->paginate(20);
     return view('blogs.show', $data);
 }