Professional Documents
Culture Documents
Inventory Database Design
Inventory Database Design
Tables:
Objectives for database design for Tshirt Design company 1) Customer table
3) products table
id Customer name email id Custom Product attribut Variation stock
4) Attribute table er id id e id id
1 A A@yahoo.com 1 1 3 2 4 15
5) Variation table 2 1 3 2 5 4
2 B B@gmail.com
3 1 5 6 13 13
id Customer id Product id attribute id Variation Stock Q) Print the invoice for each customer A and B 4 2 4 5 14 25
id
Output
1 1 3 2 4 15
2 1 3 2 5 4
Customer name product type quantity
3 1 5 5 13 13
a Oil Palm oil 30 ml
4 2 4 5 14 25 Olive oil 60 ml Based on the information provided, it
seems that the relationship between the
id Product name "product purchase" table and the
water soft 60 ml
3 Oil hard 80 ml "products" table can be inferred as follows:
4 Water
1. The "product purchase" table has a
5 Fruit "belongsTo" relationship with the
"products" table.
Answer:
- The "product purchase" table has a
column named "Product id", which likely
customer can purchase many products
represents a foreign key referencing the
"id" column in the "products" table.
A customer hasMany product Purchase
- Each row in the "product purchase"
table corresponds to a specific product
purchase, and it is associated with a single
product from the "products" table.
id Customer id Product id attribute id Variation Stock
id 2. The "products" table has a "hasMany"
id attribute name Product id Total Stock 1 1 3 2 4 15 relationship with the "product purchase"
table.
1 Olive oil 3 28 2 1 3 2 5 4
- The "products" table has an "id"
2 Palm oil 3 116 3 1 5 6 13 13 column, which serves as the primary key
3 Hard Water 4 940 for the products.
- Each product in the "products" table
4 Green 5 254 may have multiple associated product
5 Soft Water 4 170 purchases in the "product purchase" table.
13 6 20 kg 180 12
14 5 20 ml 254 15
Solution
$customer_product_purchases = ProductPurchase::with('customer')
->with('product')
->with('attribute')
->with('variation')
->get();
echo '<table>';
echo '<thead>';
echo '<tr>';
echo '<th>Product Purchase ID</th>';
echo '<th>Customer Name</th>';
echo '<th>Customer Email</th>';
echo '<th>Product Name</th>';
echo '<th>Attribute Name</th>';
echo '<th>Variation</th>';
echo '</tr>';
echo '</thead>';
echo '<tbody>';
// dd($customer_product_purchases);
$customer_ids = [];
// dd($customer_product_purchases);
foreach($customer_product_purchases as $key => $product){
// dd($product->attribute->attribute_name);
if(in_array($product->customer->id,$customer_ids,)){
// dd($product->customer->Customer_name);
echo '<tr></tr>';
echo '<td rowspan="1">'.'</td>';
echo '<td rowspan="1">'. '</td>';
echo '<td>' . $product->customer->email . '</td>';
echo '<td>' . $product->product->Product_name . '</td>';
echo '<td>' . $product->attribute->attribute_name . '</td>';
echo '<td>' . $product->variation->variation . '</td>';
echo '<td>' . $product->stock . '</td>';
echo '</tr>';
}
else{
array_push($customer_ids,$product->customer_id);
echo '<tr>';
echo '<td>'. count($customer_ids) .'</td>';
echo '<td>' . $product->customer->Customer_name . '</td>';
echo '<td>' . $product->customer->email . '</td>';
echo '<td>' . $product->product->Product_name . '</td>';
echo '<td>' . $product->attribute->attribute_name . '</td>';
echo '<td>' . $product->variation->variation . '</td>';
echo '<td>' . $product->stock . '</td>';
echo '</tr>';
}
}
});
Output: