public function run() { DB::table('order_items')->delete(); OrderItem::create(array('order_id' => '1', 'product_id' => '1', 'price' => '1000', 'quantity' => '4')); OrderItem::create(array('order_id' => '1', 'product_id' => '2', 'price' => '2000', 'quantity' => '4')); OrderItem::create(array('order_id' => '2', 'product_id' => '3', 'price' => '3000', 'quantity' => '1')); OrderItem::create(array('order_id' => '2', 'product_id' => '1', 'price' => '1000', 'quantity' => '2')); OrderItem::create(array('order_id' => '3', 'product_id' => '1', 'price' => '1000', 'quantity' => '2')); }
public function run() { DB::table('order_items')->delete(); for ($i = 0; $i < $this->num_records; $i++) { $array = ["order_id" => $this->getRandRec(), "product_id" => $this->getRandRec(), "quantity" => $this->getFaker()->numberBetween($min = 1, $max = 20), 'price' => $this->getFaker()->randomFloat($nbMaxDecimals = 2, $min = 0, $max = 100)]; OrderItem::create($array); } }
public function addItem($product_id, $quantity) { $product = Product::findOrFail($product_id); $params = ['order_id' => $this->id, 'product_id' => $product->id, 'quantity' => $quantity, 'price' => $product->price * $quantity]; return OrderItem::create($params); }