/**
  * 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);
 }
 /**
  * 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];
     });
 }
Exemple #3
0
 public function scopeStatus($query, $status)
 {
     $state_id = OrderState::where('name', $status)->pluck('id');
     return $query->where('state_id', $state_id);
 }
 /**
  * Call: PUT (/orders/{orders}/deactivate)
  *
  * Deactivate an order. This will serve for: declining an order (before it's been processed) and cancelling it (after it's been processed)
  * In bothe cases, we call delete() method on a model, which soft-deletes a record (sets the deleted_at timestamp). So if an employee does
  * one of above mentioned actions, you should call this function.
  * @param $id
  */
 public function deactivate($id)
 {
     $order = Order::find($id);
     $state = $order->state()->first();
     if ($state->name == 'pending') {
         $order->state_id = OrderState::where('name', 'declined')->first()->id;
         $order->acquired_by = auth()->user()->userable_id;
         $order->save();
         $order->delete();
         return redirect('/')->with('message', 'Uspešen preklic naročila.');
     } else {
         $order->state_id = OrderState::where('name', 'cancelled')->first()->id;
         $order->save();
         $order->delete();
         return redirect('/')->with('message', 'Uspešen storno naročila.');
     }
 }