public function run() { Model::unguard(); DB::statement('SET FOREIGN_KEY_CHECKS = 0'); DB::table('orderitems')->truncate(); $faker = Faker::create(); $orders = \App\Models\Orders::all()->lists('id'); $vendors = \App\Models\Vendors::all()->lists('id'); $categories = \App\Models\Categories::all()->lists('id'); foreach (range(1, 20) as $index) { $quantity = $faker->numberBetween(1, 20); $price = $faker->randomFloat(2, 1, 5000); $finalprice = $faker->randomFloat(2, 1, 5000); DB::table('orderitems')->insert(['name' => $faker->name, 'order_id' => $faker->randomElement($orders), 'category_id' => $faker->randomElement($categories), 'vendor_id' => $faker->randomElement($vendors), 'description' => $faker->text(), 'url' => $faker->url, 'quantity' => $quantity, 'estimatedprice' => $price, 'estimatedtotal' => $price * $quantity, 'fixedprice' => $finalprice, 'fixedtotal' => $finalprice * $quantity, 'status' => 0]); } DB::statement('SET FOREIGN_KEY_CHECKS = 1'); }
public function rules($id = '') { switch (Request::method()) { case 'GET': case 'DELETE': return []; case 'POST': return $rules = ['name' => 'required|unique:Vendors']; case 'PUT': case 'PATCH': $vendor = Vendors::find($id); return $rules = ['name' => 'required|unique:Vendors,id,' . $vendor->id]; default: break; } }
/** * Finds the Vendors model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Vendors the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Vendors::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { $order = Orders::find($id); return view('admin.orders.order_edit', ['order' => $order, 'allCategories' => Categories::lists('name', 'id'), 'allVendors' => Vendors::lists('name', 'id'), 'approvalPermissionUsers' => User::findAllWithAccess(['admin,approval.*'])]); }
/** * @return \yii\db\ActiveQuery */ public function getVendor() { return $this->hasOne(Vendors::className(), ['id' => 'vendor_id']); }