Exemplo n.º 1
0
 public function getHistorico()
 {
     $sale = Transaction::whereHas('book', function ($q) {
         $q->where('id_user', '=', \Auth::user()->id);
     })->get();
     $sale->sum('price');
     $myRental = Aluguer::whereHas('book', function ($q) {
         $q->where('id_user', '=', \Auth::user()->id);
     })->get();
     $purchases = Purchase::where('user_id', '=', \Auth::user()->id)->get();
     $rental = Aluguer::where('user_id', '=', \Auth::user()->id)->get();
     $user = \App\User::find(\Auth::user()->id);
     return view('historico', ['purchases' => $purchases, 'sales' => $sale, 'rentals' => $rental, 'myRentals' => $myRental, 'user' => $user]);
 }
Exemplo n.º 2
0
 public function saveAluguer($articles, $payment_id)
 {
     foreach ($articles as $article) {
         if ($article['option'] == 'rent' && $article['days'] > 0) {
             $rent = new Aluguer();
             $rent->start = date('Y-m-d H:i:s');
             $rent->end = date('Y-m-d H:i:s', strtotime('+' . $article['days'] . ' days', strtotime($rent->start)));
             $rent->book_id = $article['id'];
             $rent->user_id = Auth::user()->id;
             $rent->payment_id = $payment_id;
             $rent->save();
         } else {
             $purchase = new Purchase();
             $purchase->book_id = $article['id'];
             $purchase->user_id = Auth::user()->id;
             $purchase->payment_id = $payment_id;
             $purchase->save();
         }
     }
 }