/**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(QuestionRequest $request)
 {
     $this->askQuestion($request);
     $question = Questions::where('question', $request->input('question'))->get();
     $count = Questions::where('question', $request->input('question'))->count();
     flash('Your Question Has Been Posted');
     return redirect(action('QuestionsController@show', $question[$count - 1]->slug));
 }
Exemplo n.º 2
0
 public function get_all_questions()
 {
     $questions = Questions::where('questions.id', '>', 0)->leftJoin('answers', 'questions.id', '=', 'answers.question_id')->selectRaw('questions.*, count(answers.id) as total_answers')->groupBy('questions.id')->orderBy('questions.created_at', 'dec')->get();
     if (count($questions) > 0) {
         return $questions;
     } else {
         return "";
     }
 }
Exemplo n.º 3
0
 public function index()
 {
     if (Auth::check()) {
         $data['questions'] = Questions::all();
     } else {
         $data['questions'] = Questions::where('status', '0002')->get();
     }
     return view('questions/questionsList', $data);
 }
Exemplo n.º 4
0
 public function searchTag($tag)
 {
     if ($tag == "null") {
         $view = QAController::index();
     } else {
         //Gathers Questions where the tags are alike with the tags given.
         $questions = Questions::where('tags', 'LIKE', "%{$tag}%")->orderBy('id', 'desc')->paginate(10);
         $questions->setPath('QA');
         //creating view accordingly attaching questions that we have gathered with.
         $view = view('QA.index')->with('questions', $questions);
     }
     //renders section in view and for ajax setting the related section(content).
     $sections = $view->renderSections();
     return $sections['content'];
 }
Exemplo n.º 5
0
 public function adminViewCourse($courseid)
 {
     $course = Courses::find($courseid);
     if (count($course) < 1) {
         return view('errors.404');
     }
     //        $result = array('Title' => $course['Title']);
     $course = $course->toArray();
     $posts = Posts::where('CourseID', '=', $courseid)->get()->toArray();
     $numQuestions = [];
     foreach ($posts as $p) {
         $numQuestions += [$p['id'] => count(Questions::where('PostID', '=', $p['id'])->get()->toArray())];
     }
     $r = array('posts' => $posts);
     $r += array('Title' => $course['Title']);
     $r += array('NumQuestions' => $numQuestions);
     $r += array('CourseID' => $courseid);
     //        return var_dump($r);
     //        dd($r);
     return view('viewcourse', $r);
 }
Exemplo n.º 6
0
 public static function destroy($id)
 {
     if (!AuthController::checkPermission()) {
         return redirect('/');
     }
     $post = Posts::find($id);
     @unlink(public_path('images/imagePost/' . $post['Photo']));
     $questions = Questions::where('PostID', '=', $id)->get()->toArray();
     foreach ($questions as $question) {
         QuestionsController::destroy($question['id']);
     }
     $courseid = $post['CourseID'];
     $post->delete();
     $course = Courses::find($post->CourseID);
     $course->NoOfPosts--;
     $course->update();
     return redirect(route('admin.viewcourse', $courseid));
 }