I want to write a method to save the history of changes in the table. I have three tables (products, articles and categories). When a user makes a change, for example in the product name. I want to display a message at the product, example: User Jack change the name of product with "ball" on the "ball2016."
I came up with that I created new pivot table "history_products" wherein the columns will: "user_id", "products_id", "created_at" and "updated_at". This table will be connected with table products. I want to used this trigger. You think it's a good idea or in a Laravel can do it in an easier way??
a good source/library is revisionable, the following:
VentureCraft/revisionable
Related
I am developing an online inventory management system. I have one table for the main inventory which consists of the product names, quantity and barcodes etc. I want users to log into the system each morning and log the quantity of each item they take. I then want to store this information for the admin to view. I have developed the system so that a new table gets created each morning based on the users name and date. This is allows the user to input the quantity for each product, i then subtract that column from the main inventory table when the user clicks submit. I want to know if this is a bad practice, is it necessary to create a new table each morning? If not what method should i use?
I think you should maintain a single table for inventory, and then after a create a temporary table to store the list of items the user takes which will contain the user id, inventory id, qty etc, and then update the quantity of inventory in inventory table, whenever user picks the inventory.
In short you should create a single table to store the information of inventory which user takes instead of creating a new table each day.
Insert and fetch data according to date + user.
I wonder if you are creating new table everyday, you should not create new table in any case. In the rarest scenario even if your columns are dynamic then create a table with rows representing as column and use pivot to fetch the record. For your use case you just need to have a table which stores a new record and subtract the count from main table.
In my application I have two tables
orders:
order_id
order_number
products:
product_id
product name
order_id(foreign key)
and in my phpmyadmin I chose order_id to display as order_number but when I render the view associated with products it displays order_id. is there any way that it can order_number instead of order_id?
According to your question, enough adding the following line in the products controller, before rendering of course.
$crud->set_relation('order_id','orders','order_number');
Yes, by configuring the Relation view you can select which column is displayed here.
From the products table, go to the Structure tab, then the Relation view sub-tab:
Set up the relation as so:
Alternatively, use the Designer tab from the database level to do the same:
(hint: I think Designer is generally easier).
Next, from the orders table go to the Relations view and find "Choose column to display" about halfway down the page; pick order_number there so phpMyAdmin knows which column you wish to display.
One last step -- back on the products table, in the Browse view, expand the Options area part way down the page. Toggle the radio button to Display column for relations and press Go.
Now when you Browse the products table, the order_number is displayed instead of the order_id.
I have one Category List user will select a category from the list if user didn't find a category in the list, then he will select "other" option and it will display a text box there user will enter a new category name. This newly added category will go for approval to Site Admin till then it should be mentioned as "Uncategorised".
So my question is how to achieve this using a mysql table should I create a new table as uncategorized category or should I add one extra column to category table as "isApproved". As the solution should be for both add and edit of new category.
As you described
Admin must approve newly added category.
To acheive that you definitely will have a field status or something like that to check if this category is approved or not. You can simply use that field. If it is not active, it is "Uncategorized.
A more flexible way than adding one isApproved (or rather a more generic name like status) column to your table is to create a whole new temporary table. There are number of reasons why this is the better approach:
You can save diagnostical information like who created this category, when did he create it, and so on.
You separate your logic: An unapproved entry is, simply put, a temporary one. Approving it is nothing more than moving it over to your categories table and thus making it permanent.
Your categories table doesn't get clustered with unnecessary entries.
I have multiple type of digital goods that can be bought from site.(Passes and tickets).
I want some suggestions regarding what should be the database structure of such payments
.Table used for storing payments is purchase history
OPTION 1
1st option can be as shown below in which item id of each product will be in seperate column.
For each payment only that column of that product is populated which is purchased .
OPTION 2
In second option Id of product will be store in 1 column and type of product in other.
Please suggest which option is better or can there be any other method which is better and efficient than these ?
Option 2 is scale-able, option 1 isn't.
If you went with option 1, then decided to add a dozen more types of products, you'll need a new table for each, a new column in purchase_history for each, and to rewrite most of your queries and reports to suit.
Option 2 allows you not to worry about this, even if you stick with just the two types of products forever - at least you've only got one column to deal with in your purchase history table.
If it were me, I'd be combining the tickets and passes tables into a "products" table, and have an ENUM or similar field to differentiate them. Sure, the tickets table has more fields which passes doesn't need - but passes doesn't have any that tickets doesn't need, and you can just make the extras nullable and leave them there. Then just use product_id in your purchase history and do away with the product type table and field completely.
I have 3 tables,
users(id) , userproduct (user_id,product_id) and product (id).
When a user adds a product their user_id and the product_id is saved in USERPRODUCT table.
Now at the same time another user can save a product (kind of like "set as favorite") for this I need to save the user_id of the user who saved it and the product_id of the product. This will create another table (call it favorites) however this table is also a resolve to the many to many relationship between "users" table and "product" table.
the question: is it possible for this, to have 2 tables resolving a many to many relationship or is there any other way to solve my issue.
if it is possible how will one be draw this in the ER diagram
it depends on what you want.
you may use only one table and design your relations with boolean fields
USERS(id)
PRODUCTS(id)
USERPROD(userid, productid, isbought, isfavorite, isowned)
or you may use one many-to-many support table for every relation is up to you
maybe you want another field "owner" in PRODUCTS table to store the user id. this is a one-to-one relation
What you want to do is actually describe the kind of relation between user and product: a favorite, or he 'owns' it.
Just add another field to the userproduct-table defining the relation: favorite or owned