Let’s say in your case, we need to define the category for every features. So feature can have many categories and inverse category can have many features. Thus, it will be a Many To Many relationships.
To accomplish this we need to create 3 tables features, categories, and intermediate table feature_category. The feature_category table will have the feature_id and category_id column which connects both feature and category table and this intermediate table called the pivot table.
Here are the table structures:
features
id - integer
name - string
categories
id - integer
name - string
feature_category
feature_id - integer
category_id - integer
=> category
id name
-- -------
1 Category 1
2 Category 2
3 Category 3
4 Category 4
=> features
id name
-- -------
1 Feature 1
2 Feature 2
3 Feature 3
4 Feature 4
Checkboxes or dropdowns can be used from the frontend to select multiple categories for features and sync() method can be used to update feature cards accordingly.
2
Answers
Let’s say in your case, we need to define the category for every features. So feature can have many categories and inverse category can have many features. Thus, it will be a Many To Many relationships.
To accomplish this we need to create 3 tables
features
,categories
, and intermediate tablefeature_category
. Thefeature_category
table will have thefeature_id
andcategory_id
column which connects both feature and category table and this intermediate table called the pivot table.Here are the table structures:
=> category
=> features
=> feature_category
===============================
Our feature_category table before sync() operation:
Laravel Sync() example:
After performing the above operation, our feature_category table will look like below:
Checkboxes or dropdowns can be used from the frontend to select multiple categories for features and sync() method can be used to update feature cards accordingly.
First you need to create new table
feature_category
with two fields :Second create
belongsToMany
relationship directly in Voyager.Example :