public function getQuesitions(Request $request) { $type = $request->get('type'); switch ($type) { case 0: $questions = Question::take(10)->get(); break; case 1: $questions = Question::orderBy('total_answer', 'desc')->take(10)->get(); break; case 2: $questions = Question::where('issolved', 0)->take(10)->get(); break; default: $questions = Question::where('issolved', 1)->take(10)->get(); break; } if ($questions) { foreach ($questions as &$question) { $question['time'] = $question->created_at->diffForHumans(); $question['username'] = $question->user->name; } $this->setResult($questions); $this->succeed(true); } else { $this->setResult('questions表获取记录失败!'); $this->fail(true); } }
/** * Display a listing of the resource. * * @return Response */ public function index(Request $request) { if ($request->has('filterBy')) { $questions = Question::with('state')->where($request->get('filterBy') . '_id', $request->get('id'))->get(); } else { $questions = Question::orderBy('likes', 'desc')->with('state')->get(); } $states = State::lists('name', 'id'); return view('admin.questions.index', compact('questions', 'states')); }
/** * Show the application dashboard to the user. * * @return Response */ public function index() { if (Auth::user()) { $countryId = Auth::user()->country_id; } else { $location = GeoIPFacade::getLocation(); $countryId = Country::where('country_code', '=', $location['isoCode'])->first()->id; } $questions = Question::whereNotNull('questions.user_id')->whereNotNull('questions.question_category_id')->whereNotNull('questions.country_id')->where('questions.is_displayed', '=', 1)->where('questions.country_id', '=', $countryId)->where('questions_countries.country_id', '=', $countryId)->with('author')->with('category')->with('country')->join('questions_countries', 'questions.id', '=', 'questions_countries.question_id')->orderBy('questions_countries.count', 'DESC')->limit(5)->get(); $allQuestions = Question::orderBy('updated_at', 'DESC')->paginate(10); return view('pages.home', compact('questions', 'allQuestions')); }
/** * creating an new question. * * @return Response */ public function getQuestion() { $questions = \App\Question::orderBy('created_at', 'DESC')->get()->toArray(); return response()->json($questions); }
public function showAllQuestions() { $questions = Question::orderBy('id', 'desc')->get(); return view('questions.all-questions', compact('questions')); }
/** * @param string $order_by * @param string $sort * @return mixed */ public function getAllQuestions($order_by = 'id', $sort = 'asc') { return Question::orderBy($order_by, $sort)->get(); }