Wordsmith - adding categories and tags

dave-armstrong ãƒŧ

Jan 25th, 2022 02:05 PM

What's the correct way to retrofit/add categories and tags to a blog once it's already set up. I know this should have been scoped prior to the building but these things happen ðŸĪŠ

bobbyiliev ãƒŧ

Jan 25th, 2022 10:07 PM


Best Answer

Hey there Dave,

This should not be a problem, things like that happen to me all the time :D

I would assume that you are using Laravel. If this is the case, what you could do is to just add a new categories table where you would store your categories and then create a category_id column in your posts table. That way you will be able to have a belongsTo relationship for your posts and categories.

For the tags, a quick way to do it is to just add a tags column to your posts table and have the tags stored as plain text separated by coma. Alternatively you could create a many to many relation to store the tags in a separate table and have a pivot table to store the relation between your posts and tags.

You can add the new columns and tables using the standard Laravel migrations:

Laravel Migrations



dave-armstrong ãƒŧ

Jan 28th, 2022 07:32 AM

Thanks Bobby, Yeah, I was trying out the wordsmith videos. (last few have full screen disabled).

I think I've relied on voyager too much regarding belongs to relationships! Voyager makes it so easy but this will be good for me hahaha.

Thanks for the response!

bobbyiliev ãƒŧ

Jan 28th, 2022 07:43 AM

Hey Dave,

No problem at all! Let me know how it goes!

I've also been a fan of Voyager for a very long time and I've built multiple projects using it 😁, in some cases, I find it helpful to also good to start from scratch to refresh your knowledge on migrations, relations, CRUD and etc. 🙌