/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     StateOrder::create(['name' => 'Pago pendiente']);
     StateOrder::create(['name' => 'Confirmado']);
     StateOrder::create(['name' => 'En camino ']);
     StateOrder::create(['name' => 'Entregado']);
 }
 public function showBackProvider()
 {
     $user = Auth::user();
     $orders = Order::whereHas('products', function ($query) use($user) {
         $query->where('products.user_id', $user->id);
     })->with(['products' => function ($q) use($user) {
         $q->where('products.user_id', $user->id)->with('offers');
     }, 'user'])->get();
     foreach ($orders as $order) {
         $order->quantityProducts = count($order->products);
         $order->totalValueProducts = 0;
         foreach ($order->products as $product) {
             $value = 0;
             foreach ($order->products as $product) {
                 $value += $product->totalValue = $product->pivot->value * $product->pivot->quantity;
             }
             $order->total = $value;
         }
     }
     $states = StateOrder::lists('id', 'name');
     return view('back.ordersProvider', compact('orders', 'states'));
 }