Friday, March 10, 2017

Laravel: Single or Multiple mysql tables for different Announcement types

Good day to everyone reading this. I do need advice on a project I'm working on. I'm relatively new to programming in PHP and MySQL, and I heard working on projects is the best way to brush up my skills.

The project is a simple announcements project where users can login register new announcements. Now, each announcement is based upon a category e.g. Birthdays, Weddings, Social functions, Court hearing etc.

One thing I'm currently caught up with is how the MYSQL table structure would look like. For instance, if a user wants to make a birthday post, all the user clicks is birthday and fills a form with relevant information. If a user wants to make a wedding post, the user clicks weddings and fills a form with relevant information.

However, the way I have this setup, I have a different data table for each announcement. i.e. Each announcement type is stored in its own table.

For instance for birthdays, I created a Birthday model with a BirthdaysController
For weddings, I created a Wedding model with a WeddingsController.
For graduation, I created a Graduation model with a GraduationController.

But some of the announcements share similar attributes like name, title, etc.

But this however would imply repeating a lot of code since they share similar attributes e.g. a birthday announcement would most likely be similar to a graduation announcement.

My first question is how do I limit the number of tables I have to create and reduce code so it doesn't look repetitive.

From my point of view, I have way too many models and controller. More so, I find I am repeating codes, and in "Object Oriented Boot camp" from Laracast, I can vividly remember Jeff stated this is a bad practice. So I really am looking for a better way to do this. I know this is quite lengthy, but please I do need help on this.

Thanks.



via Ian

Advertisement