I have 3 tables: Questions, Answers & Ratings
I want to join the answers
table with questions
table where questions.id = answers.question_id
and ratings
table to answers
table where answers.id = ratings.answer_id
But it returns null
$allQuestionWithAnswerAndRating = DB::table('questions')->orderBy('questions.id','desc' )
->join( 'answers', 'questions.id' , '=' , 'answers.question_id' )
->where('answers.user_id', '=' ,Auth::user()->id )
->join( 'ratings', 'answers.id' , '=' , 'ratings.answer_id')
->select( 'questions.id as id' , 'questions.body as question' , 'answers.body as answer' ,'answers.user_id as user_id')
->get();
What is wrong with this code?
Thanks