Part 35 – Building Our Tag Model [How to Build a Blog with Laravel 5 Series]

Now that we understand Many-To-Many Relationships, its time to implement them into our project. In this video we will be building a tag model and connecting it into our posts model so that Laravel understands its’ many-to-many status. We must first build our tag model and create a database table for our tags. Our database structure will simply consist of the name of the tag, a primary id, and timestamps. Once we have completed our tags model then we can connect it to our post model. Just like last time, we want to go into our posts model and create a new public function and tell it belongsToMany(‘App\Tag’); This tells laravel that our posts have many tags. Now we must do the inverse and tell Laravel that our Tags have many posts. To do this, we make the same statement we did in our pos

It's only fair to share...Tweet about this on TwitterShare on FacebookShare on TumblrShare on Google+Digg thisShare on LinkedInPin on PinterestShare on VKShare on RedditPrint this pageEmail this to someone
Flattr the authorShare on StumbleUponShare on YummlyBuffer this page

Leave a Reply

Your email address will not be published. Required fields are marked *