Use ->toSql ();
Nov 25, 2019
10
Level 4
Can't see the complete query so I don't know what's wrong
I have the following function: public function second($degree_id) {
$question = DB::table('questions')
->select('questions.question_text','questions.answer_time_minutes','questions.answer_time_seconds')
->join('universities', 'universities.university_id', 'questions.university_id')
->orderByRaw('RAND()')
->where('questions.degree_id', $degree_id)
->take(1)->first();
return view('2ndscreen', compact('question'));
}
This query it is supposed to:
- Get some columns from question table (question_text, questions.answer_time_minutes and questions.answer_time_seconds)
- Match university_id columns from questions and universities tables
- Random order
- Show the questions whose questions.degree_id is equal to the value passed through the function.
Is there any way to see this query in raw format so I can find out what's wrong?
Thank you
Level 2
DB::enableQueryLog();
$question = DB::table('questions')
->select('questions.question_text','questions.answer_time_minutes','questions.answer_time_seconds')
->join('universities', 'universities.university_id', 'questions.university_id')
->orderByRaw('RAND()')
->where('questions.degree_id', $degree_id)
->take(1)->first();
dd(DB::getQueryLog());
Also try,
$question = DB::table('questions')
->select('questions.question_text','questions.answer_time_minutes','questions.answer_time_seconds')
->join('universities', 'universities.university_id', 'questions.university_id')
->orderByRaw('RAND()')
->where('questions.degree_id', $degree_id)
->take(1)->toSql();
Please or to participate in this conversation.