Laravel 4 return wrong id after join table


To solve this we could add a select clause to only select the specific columns:

$exams = Exam::select(‘exams.*’)->where(function($query){
$user = Sentry::getUser();
if (!$user->hasAnyAccess([‘admin’])) {
$query->where(‘user_id’, ‘=’, $user->id);
}
})->join(‘exams_questions’,function($join) use ($question_id) {
$join->on(‘exams_questions.exam_id’, ‘=’, ‘exams.id’)
->where(‘exams_questions.question_id’, ‘=’, $question_id);
})->with(array(‘user’, ‘exam_questions’))->paginate(10);

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s