Following are the structure of my tables
Table 'categories'
'id','category_name'
Table 'user_categories'
'id', 'user_id', 'category_id'
Table 'user_category_choices'
'id','user_category_id','college_id','choice'
Table 'colleges'
'id','college_name'
User is basically a student here. User can apply to multiple categories hasMany relation. Then applying for every category, they can choose multiple colleges with choices (preference in numbers i-e 1,2,3). So what I want to get collection of all categories user applied for along with college names in order of choice.
I can get all choices for users in user model
public function choices()
{
return $this->hasManyThrough('App\UserCategoryChoice', 'App\UserCategory', 'user_id', 'user_category_id');
}
Also can get categories along with names using this
public function applies()
{
return $this->hasMany('App\UserCategory');
}
But how to get all categories applied for along with college names.
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2URCjvW
via IFTTT
Aucun commentaire:
Enregistrer un commentaire