コード例 #1
0
 public function home()
 {
     $data['users'] = User::get()->count();
     $data['fusers'] = User::whereSex('female')->get()->count();
     $data['posts'] = Post::get()->count();
     $data['cposts'] = Post::whereType('0')->get()->count();
     $data['cpoll'] = Question::orderBy('id', 'desc')->first();
     $data['vfcpoll'] = UsersAnswer::whereQuestionId($data['cpoll']->id)->get()->count();
     $posts = PostReport::select(DB::raw('post_id, count(*) as rcount'))->groupBy(['post_id'])->orderBy('rcount', 'desc')->get();
     $data['rposts'] = '';
     $i = 0;
     foreach ($posts as $key) {
         $post = Post::find($key->post_id);
         $data['rposts'][$i++] = ['id' => $post->id, 'text' => $post->post, 'uid' => $post->user_id, 'disable' => User::find($post->user_id)->disable, 'type' => $post->type, 'total' => $key->rcount, 'r1' => PostReport::wherePostId($post->id)->whereReportId(1)->get()->count(), 'r2' => PostReport::wherePostId($post->id)->whereReportId(2)->get()->count(), 'r3' => PostReport::wherePostId($post->id)->whereReportId(3)->get()->count()];
     }
     return View::make('admin.home', $data);
 }
コード例 #2
0
 public function give_answer()
 {
     try {
         $option = QuestionOption::find(Input::get('optid'));
         if ($option == null) {
             return Redirect::to('/');
         }
         $answer = UsersAnswer::whereUserId(Auth::user()->id)->whereQuestionId($option->question_id)->first();
         if ($answer == null) {
             $answer = new UsersAnswer();
             $answer->user_id = Auth::user()->id;
             $answer->question_id = $option->question_id;
             $answer->option_id = $option->id;
             if ($answer->save()) {
                 return Redirect::to('/');
             }
         }
     } catch (Exception $e) {
     }
     return Redirect::to('/');
 }