I have 3 table which is
user_answer table==> id qid content
user_question table==> id title
user_question_count table=> id answer_num
public function question()
return $this->hasOne('App\Models\UserQuestion', 'id', 'qid');
public function counts()
return $this->hasOne('App\Models\UserQuestionCount', 'id', 'id');
public function answer()
return $this->hasMany('App\Models\UserAnswer', 'qid', 'id');
$questions = UserQuestion::doesntHave('answer')->get();
doesntHave are made to check if a model has or doesn't have a relationship linked to it.
The documentation is available here if you scroll down a bit.
By the way, you should name your relationship
answers and not
answer since it's a One to Many.