Definitely not, no. Don’t store custom attributes as columns in your (product? user? something else?) table. You’d only end up with a table containing thousands of columns, which severely impacts your database performance and is completely impossible to manage.
Instead, I would have a separate table to store such attributes. Let’s say your main model is Product and the table is products. I would then make a ProductAttribute model and a corresponding product_attributes table that has the columns id, product_id, name, and value (plus timestamps if you need them). Make a unique index from product_id + name if you only want users to be able to add one instance of each custom field to each product.
Any custom fields your users add will then simply be a row in this table; e.g.,
// products
| id | name |
|----|---------|
| 1 | Shirt |
| 2 | T-shirt |
| 3 | Jeans |
// product_attributes
| id | product_id | name | value |
|----|------------|-------|-------|
| 1 | 1 | color | Blue |
| 2 | 1 | size | M |
| 3 | 2 | color | Green |
| 4 | 2 | size | L |
In your Product model, you then have a simple relationship to load all custom attributes, which you can eager-load to get everything at once:
// Product model
public function custom_attributes() {
return $this->hasMany(ProductAttributes::class);
}
// Controller
$products = Product::with('custom_attributes')->where(...)->get();