예제 #1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $employee_ids = Employee::all()->lists('id')->toArray();
     $order_states = OrderState::lists('id')->toArray();
     $products = Product::all();
     $municipalities = Municipality::all();
     factory(App\Customer::class, 50)->create()->each(function ($customer) use($employee_ids, $products, $municipalities, $order_states) {
         shuffle($employee_ids);
         shuffle($order_states);
         $customer->user()->save(factory(User::class, 'customer')->create());
         $customer->city_id = $municipalities->shuffle()->first()->id;
         $customer->save();
         $customer->products()->attach($products->shuffle()->first(), ['vote' => rand(1, 5), 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()]);
         $customer->orders()->save(factory(App\Order::class)->create(['acquired_by' => $employee_ids[0], 'state_id' => $order_states[0]]));
     });
     $user = new User();
     $user->name = 'Vid';
     $user->surname = 'Mahovic';
     $user->email = '*****@*****.**';
     $user->password = '******';
     $user->verified = true;
     $user->save();
     $customer = new Customer();
     $customer->street = 'Celovška 21';
     $customer->city_id = $municipalities->shuffle()->first()->id;
     $customer->phone = '+38640850993';
     $customer->save();
     $customer->user()->save($user);
 }
예제 #2
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $order_states = OrderState::lists('id')->toArray();
     $customer_ids = Customer::lists('id')->toArray();
     $employee_ids = Employee::lists('id')->toArray();
     $products = Product::all();
     factory(App\Order::class, 80)->create()->each(function ($order) use($customer_ids, $employee_ids, $order_states, $products) {
         $order->products()->attach($products->shuffle()->first(), ['quantity' => rand(1, 30), 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()]);
         $order->ordered_by = shuffle($customer_ids)[0];
         $order->acquired_by = shuffle($employee_ids)[0];
         $order_key = array_rand($order_states);
         $order->state_id = $order_states[$order_key];
     });
 }