laravel - (laravel4) pulling data from pivot table -



laravel - (laravel4) pulling data from pivot table -

i tried refrain myself asking stupid question 1 time again, here am...

so want check if id in pivot table (tutorial_id) matches id. however, have no thought how to id pivot table.. tried:

controller:

class tagcontroller extends basecontroller { public function gettutorials($tag) { $tag_id = tag::where('name', $tag)->first(); $tutorials = tutorial::with('tags')->where('tutorial_id', '=', $tag_id->id)->get(); homecoming view::make('tutorials/tags', array( 'tutorials' => $tutorials )); } }

tutorial model:

class tutorial extends eloquent { protected $table = 'tutorials'; public function tags() { homecoming $this->belongstomany('tag', 'tutorials_tags', 'tutorial_id'); } }

tag model:

class tag extends eloquent { protected $table = 'tags'; public function tutorials() { homecoming $this->belongstomany('tutorial', 'tutorials_tags', 'tag_id'); } }

database looks this:

error:

sqlstate[42s22]: column not found: 1054 unknown column 'tutorial_id' in 'where clause' (sql: select * `tutorials` `tutorial_id` = 1)

so want tutorials tag_id->id, can this: $tag_id->tutorials

i reformatted code you:

public function gettutorials($tag) { $tag = tag::where('name', $tag)->first(); homecoming view::make('tutorials/tags', array( 'tutorials' => $tag->tutorials )); }

reference: http://vegibit.com/many-to-many-relationships-in-laravel/

laravel

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -