本文整理汇总了PHP中Question::orderBy方法的典型用法代码示例。如果您正苦于以下问题:PHP Question::orderBy方法的具体用法?PHP Question::orderBy怎么用?PHP Question::orderBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Question
的用法示例。
在下文中一共展示了Question::orderBy方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
/**
* Display a listing of the resource.
* GET /questions
*
* @return Response
*/
public function index()
{
if (Input::has('onlyAnswered')) {
return Question::has('answer')->with('answer')->orderBy('created_at', 'DESC')->get();
}
if (Input::has('best')) {
return Question::orderByRaw('RAND()')->take(3)->get();
}
return Question::orderBy('created_at', 'DESC')->get();
}
示例2: home
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);
}
示例3: getViewresult
public function getViewresult()
{
$result = Results::where('user_id', Auth::user()->id)->first();
$result = Results::find($result['id']);
$data['pageTitle'] = "Quizzler | Dashboard";
$data['urlAddBack'] = "backends/dashboard";
$data['btnAddBack'] = '<i class="icon-reply"></i><span>Back<span>';
$data['labelPage'] = "The Quizzler Result";
$data['questions'] = Question::orderBy('id', 'desc')->get();
$data['formOrigin'] = 'quizz';
$data['activeD'] = 'active';
$result = Results::where('user_id', Auth::user()->id)->first();
$result = Results::find($result['id']);
$data['resultActive'] = $result->active;
if ($result->score >= 50) {
$data['resultScore'] = " Your scored " . $result->score . " %, You Passed.";
} else {
$data['resultScore'] = " Your scored " . $result->score . " %, You Failed.";
}
$data['resultQuestionId'] = json_decode($result->question_quizzler_answer);
return View::make('backends.dashboard.result', $data);
}
示例4: function
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/
Route::get('/', function () {
$questions = Question::orderBy('created_at', 'desc')->get();
return View::make('index')->with('questions', $questions);
});
Route::post('/', function () {
$body = Input::get('question');
if (!empty($body)) {
$answer = Answer::orderByRaw("RAND()")->get()->first();
Question::create(array('body' => $body, 'answer' => $answer->body));
}
$questions = Question::orderBy('created_at', 'desc')->get();
return View::make('index')->with('questions', $questions);
});
示例5: carnival
public function carnival()
{
//return 'We Are Working';
//Changed
$data['date'] = $this->getBaseDateTime();
/*19-May-2015 Ehsan*/
$user = User::find(Auth::user()->id);
$url = Picture::find($user->picture);
$data['self'] = $url;
/*!!!!19-May-2015 Ehsan*/
// Everyday Question Generation
$data['question'] = null;
$data['prev_question'] = null;
$question = Question::orderBy('id', 'desc')->first();
$prev_question = Question::orderBy('id', 'desc')->skip(1)->first();
if ($question) {
$data['question'] = $question;
$data['options_of_question'] = QuestionOption::whereQuestionId($question->id)->get();
//$get_count_of_the_answers = DB::table('users_answers')->select(DB::raw('option_number,count(*) as count'))->join('question_options','users_answers.option_id', '=', 'question_options.id')->whereQuestionId($question->id)->groupBy('option_id')->groupBy('option_number')->orderBy('option_number')->get();
$data['answered'] = UsersAnswer::whereUserId(Auth::user()->id)->whereQuestionId($question->id)->first();
}
if ($prev_question) {
$data['prev_question'] = $prev_question;
$options_of_question = QuestionOption::whereQuestionId($prev_question->id)->get();
$total_answer = 0;
foreach ($options_of_question as $key) {
$current_answer = DB::table('users_answers')->select(DB::raw('count(*) as count'))->whereOptionId($key->id)->first()->count;
$total_answer += $current_answer;
$answers_count[$key->option_number] = array('option_details' => $key->option_details, 'total_answer' => $current_answer);
}
try {
foreach ($options_of_question as $key) {
$cur = $answers_count[$key->option_number]['total_answer'] * 1.0;
$percentage = $cur / $total_answer * 100.0;
$answers_count[$key->option_number]['total_answer'] = number_format((double) $percentage, 2, '.', '');
}
} catch (Exception $e) {
$answers_count[1]['total_answer'] = 33;
$answers_count[2]['total_answer'] = 33;
$answers_count[3]['total_answer'] = 33;
}
$data['total_votes'] = $total_answer;
$data['answers'] = $answers_count;
}
// ENd of Question Related Code
// Top And Flop Post Generation
$posts = Post::select('posts.*')->join('users', 'users.id', '=', 'posts.user_id')->where('users.disable', '0')->whereType('3')->orderBy('posts.id', 'desc')->take(30)->lists('id');
$top_post = DB::table('likes')->select(DB::raw('count(*) as like_count, post_id'))->whereIn('post_id', $posts)->orderBy('like_count', 'desc')->groupBy('post_id')->first();
// return json_encode($top_post);
$flop_post = DB::table('dislikes')->select(DB::raw('count(*) as dislike_count, post_id'))->whereIn('post_id', $posts)->orderBy('dislike_count', 'desc')->groupBy('post_id')->first();
$data['flop_post'] = null;
$data['top_post'] = null;
if ($top_post) {
$post = Post::whereId($top_post->post_id)->first();
/*19-May-2015 Ehsan*/
$user = User::find($post->user_id);
$url = Picture::find($user->picture);
$url = $url->url;
/*!!!!19-May-2015 Ehsan*/
$text = htmlentities($post->post);
/*Eve-26-May-Ehsan*/
/*!!!!Eve-26-May-Ehsan*/
$text = preg_replace('@(https?://([-\\w\\.]+)+(:\\d+)?(/([\\w/_\\.]*(\\?\\S+)?)?)?)@', '<a target="_blank" href="$1">$1</a>', $text);
$text = preg_replace('/#([a-zA-Z0-9\\x{0980}-\\x{09FF}_])+/u', '<a href="#" class="tags">$0</a>', $text);
$text = nl2br($text);
$text = Emojione::shortnameToImage($text);
$now = Carbon::parse($post->created_at);
$data['top_post'] = array('id' => $post->id, 'post' => $text, 'user_id' => $post->user_id, 'img' => asset($url), 'like' => Like::wherePostId($post->id)->get()->count(), 'dislike' => Dislike::wherePostId($post->id)->get()->count(), 'liked' => Like::wherePostId($post->id)->whereUserId(Auth::user()->id)->get()->count(), 'disliked' => Dislike::wherePostId($post->id)->whereUserId(Auth::user()->id)->get()->count(), 'comment' => Comment::wherePostId($post->id)->get()->count(), 'ago' => $now->diffForHumans());
} else {
$data['top_post'] = null;
}
if ($flop_post) {
$post = Post::whereId($flop_post->post_id)->first();
/*19-May-2015 Ehsan*/
$user = User::find($post->user_id);
$url = Picture::find($user->picture);
$url = $url->url;
/*!!!!19-May-2015 Ehsan*/
$text = htmlentities($post->post);
/*Eve-26-May-Ehsan*/
/*!!!!Eve-26-May-Ehsan*/
$text = preg_replace('@(https?://([-\\w\\.]+)+(:\\d+)?(/([\\w/_\\.]*(\\?\\S+)?)?)?)@', '<a target="_blank" href="$1">$1</a>', $text);
$text = preg_replace('/#([a-zA-Z0-9\\x{0980}-\\x{09FF}_])+/u', '<a href="#" class="tags">$0</a>', $text);
$text = nl2br($text);
$text = Emojione::shortnameToImage($text);
$now = Carbon::parse($post->created_at);
$data['flop_post'] = array('id' => $post->id, 'post' => $text, 'user_id' => $post->user_id, 'img' => asset($url), 'like' => Like::wherePostId($post->id)->get()->count(), 'dislike' => Dislike::wherePostId($post->id)->get()->count(), 'liked' => Like::wherePostId($post->id)->whereUserId(Auth::user()->id)->get()->count(), 'disliked' => Dislike::wherePostId($post->id)->whereUserId(Auth::user()->id)->get()->count(), 'comment' => Comment::wherePostId($post->id)->get()->count(), 'ago' => $now->diffForHumans());
} else {
$data['flop_post'] = null;
}
// Top And Flop Post Generation end
// Get All Available Reports and Feelings
$data['feelings'] = Feeling::get();
$data['reports'] = Report::get();
//
$data['notifications'] = $this->getNotification();
//Get Current Trends
$now = Carbon::now();
$before_12hours = Carbon::now()->subHours(12);
$data['tags'] = DB::table('hash_tagged_posts')->select('tag_id', 'tag', DB::raw('count(*) as count'))->join('hashtags', 'hashtags.id', '=', 'hash_tagged_posts.tag_id')->whereIn('hash_tagged_posts.post_id', function ($query) {
//.........这里部分代码省略.........
示例6: getIndex
public function getIndex()
{
$questions = Question::orderBy('id', 'DESC')->get();
return View::make('admin.teacher.questions.questionIndex')->with('questions', $questions);
}
示例7: getIndex
public function getIndex()
{
$question = Question::orderBy('pin', 'desc')->orderBy('pin', 'desc')->orderBy('updated_at', 'desc')->orderBy('question_id', 'desc')->get();
return View::make('faq.index')->with(compact('question'));
}
示例8: array
Mail::send('emails.test', array(), function ($message) {
//$message->from('support@cortana.dev', 'c01tana Ltd');
$message->to('rocardpp@gmail.com', 'rocard')->subject('test mail');
});
return 'done.';
});
Route::get('/', function () {
$data['users'] = User::all();
//$data['questions'] = DB::select( DB::raw("SELECT * FROM `questions` ORDER BY `created_at` DESC LIMIT 1") );
$data['questions'] = Question::orderBy('created_at', 'desc')->paginate(10);
$data['count'] = Question::all()->count();
return View::make('site.home')->with($data);
});
Route::get('questions', function () {
$data['users'] = User::all();
$data['questions'] = Question::orderBy('created_at', 'desc')->paginate(10);
$data['count'] = Question::all()->count();
return View::make('site.questions')->with($data);
});
Route::get('question/{id}/{slug}', function ($id, $slug) {
$data['users'] = User::all();
$data['qvotes'] = Qvote::where('question_id', '=', $id)->get();
$data['question'] = Question::find($id);
$data['answers'] = Answer::where('question_id', '=', $id)->orderBy('votes', 'desc')->get();
$data['comments'] = Comment::where('question_id', '=', $id)->orderBy('created_at', 'desc')->get();
$data['count'] = Answer::where('question_id', '=', $id)->count();
return View::make('site.question')->with($data);
});
Route::get('users', function () {
$data['users'] = User::orderBy('reputation', 'desc')->paginate(20);
return View::make('site.users')->with($data);
示例9: foreach
foreach ($usa->answer as $ansobj) {
$tempansarr[$ansobj->question_id] = $ansobj->answer_text;
}
foreach ($usa->categoryvendoranswer as $catansobj) {
$tempcatansarr[$catansobj->categoryvendor_id] = $catansobj->answer;
}
$useransarr[$usa->id]['login'] = $usa->email;
$useransarr[$usa->id]['id'] = $usa->id;
$useransarr[$usa->id]['answers'] = $tempansarr;
$useransarr[$usa->id]['catanswers'] = $tempcatansarr;
// dd($useransarr[]);
}
//dd($userswithanswers);
// $questions = Question::all();
// $users = User::whereIn('id', $user_ids)->get();
$questions = Question::orderBy('page')->where('event', '=', $exceleve)->where('page', '!=', 0)->orderBy('order')->get();
$categoryvendors = Categoryvendor::all();
// HEADER ROW FOR FOR EXCEL
$header1 = array();
$header1[] = '';
$header2 = array();
$header2[] = 'Login';
$preprojectnumber = '';
foreach ($questions as $header) {
/*echo $header->class_name."<br>";
echo $header->question_group."<br>";*/
if ($header->class_name != 'projects checkbox group') {
//echo "1";
$header1[] = $header->question_group;
$header2[] = $header->question_text;
} else {
示例10: getDashboard
public function getDashboard()
{
return View::make('dashboard')->withQuestions(Question::orderBy('created_at', 'DESC')->get());
}