php - How to view strings from a many-to-many relationship using blade -


tableone  id|topic 1 |football 2 |rugby 3 |cricket 4 |tennis  tabletwo  id|name 1 |bill 2 |tom 3 |sally  pivottable  id|name_id|topic_id 1 |2      |2 2 |2      |3 3 |2      |4 4 |3      |1 5 |1      |4 

first of looking @ code below have defined authenticated user 'tom'. tables above have following code:

 $authuser = auth::user(); //tom   foreach ($authuser->usersubject $chosensubjectname)   {       var_dump($chosensubjectname->name);       } 

the code above gives me following output when output browser:

string(5) "rugby"  string(7) "cricket"  string(6) "tennis" 

as can see not array , im unsure how split these 3 sets of strings. can please tell me how output in blade not collection. mean 1 topic @ time. want display 1 of choosing. e.g. 'rugby'. (laravel 4.2)

by way code below defines many-to-many relationship between tableone , tabletwo.

 public function usersubject(){         return $this->belongstomany('subjectlist', 'subjectlists_user', 'name_id', 'topic_id'); } 

thanks in advance

had post reply rather comment.

$authuser->usersubject->toarray() 

the above code give array of objects rather collection. if loading these database how going unseting variables? if trying list options user hasn't selected. try.

db::table('subjectlist')->wherenotin('id', array(1, 2, 3))->get(); 

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -