lundi 11 janvier 2021

returning empty array for my laravel relationship model. I have 2 model, SurveyQuestion and SurveyQuestionOption

SurveyQuestion Model

public function opinions(){
    return $this->hasMany('App\SurveyOpinions','option_id');
}

SurveyQuestionOption

public function options(){
   return $this->hasMany('App\SurveyQuestionOption','question_id');
  } 

Controller

public function getQuestions(){

        $data=SurveyQuestion::with('options')
                              ->get();
        
        if(count($data)>0)
    {
        return api::success(['data' => $data]);
    }
    return api::notFound(['errorMsg' => 'No Survey initiated yet!!!']);
                           
    }

When I hit get Question Api am getting an empty array. from model. I tried that by putting dd() for $data Variable.

Response



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2Xygyn3
via IFTTT

Aucun commentaire:

Enregistrer un commentaire