public function savecde()
 {
     $id = Auth::user()->id;
     if (User::find($id)->customer) {
         $customer_id = User::find($id)->customer->id;
         $num_cde = History::orderBy('cde_id', 'desc')->first()->cde_id + 1;
         foreach (Session::get('cde') as $pdts) {
             foreach ($pdts as $pdt) {
                 $product = Product::find($pdt['id']);
                 $h = new History();
                 $h->product_id = $pdt['id'];
                 $h->customer_id = $customer_id;
                 $h->cde_id = $num_cde;
                 $h->price = $product->price;
                 $h->quantity = $pdt['quantity'];
                 $h->command_at = Carbon::now();
                 $h->status = 'finalized';
                 $h->save();
                 $product->quantity -= $pdt['quantity'];
                 $product->save();
             }
         }
         $customer = Customer::find($customer_id);
         $customer->number_command += 1;
         $customer->save();
         Session::forget('cde');
         return redirect('/')->with(['message' => 'Votre commande a bien été validée sous le N° ' . $num_cde, 'alert' => 'success']);
     } else {
         return redirect('/registerCustomer');
     }
 }
 public function showHistory()
 {
     $histories = History::orderBy('command_at', 'cde_id', 'desc')->get();
     return view('admin.history', compact('histories'));
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $history = History::orderBy('id', 'desc')->paginate(10);
     $history->setPath('history');
     return view('history.index')->with('history', $history);
 }