/**
  * Responds to requests to
  */
 public function getPage($id = null)
 {
     if ($id != null) {
         // find the item in the added_items table
         $item = \App\AddedItem::where('id', '=', $id)->find($id);
         $itemAsArray = $item->toArray();
         // update the added_items table
         if ($itemAsArray) {
             $item->make_public = TRUE;
             // save changes
             $item->save();
             \Session::flash('flash_message', 'You successfully made ' . $item->item . ' public for sale!');
         }
         // add the item to the public_items table
         $publicItem = new \App\PublicItem();
         $publicItem->item = $itemAsArray['item'];
         $publicItem->category = $itemAsArray['category'];
         $publicItem->one_line_description = $itemAsArray['one_line_description'];
         $publicItem->price = $itemAsArray['price'];
         $publicItem->detailed_description = $itemAsArray['detailed_description'];
         $publicItem->user_id = \Auth::id();
         $publicItem->save();
     }
     // fetch the items from the public_items table
     $items = \App\PublicItem::where('bought', '=', 0)->get();
     //dump($items->toArray());
     $itemsArray = $items->toArray();
     //dump($itemsArray);
     return view('pongo.browse_items')->with('items', $itemsArray);
 }
 /**
  * Responds to requests to
  */
 public function getPage($id = null)
 {
     // update the public_items table and mark the item as bought
     $item = \App\PublicItem::where('id', '=', $id)->find($id);
     //dump($item->toArray());
     $price = null;
     // make sure the item isn't one that is posted by the user
     $user_id = $item['user_id'];
     if ($user_id == \Auth::id()) {
         \Session::flash('flash_message', 'You cannot purchase an item that you posted!');
         // fetch the items from the public_items table
         $items = \App\PublicItem::where('bought', '=', 0)->get();
         //dump($items->toArray());
         $itemsArray = $items->toArray();
         //dump($itemArray->toArray());
         // calculate the tax and total
         return view('pongo.browse_items')->with('items', $itemsArray);
     }
     $price = $item['price'];
     //echo $price;
     $tax = round($price * 0.1, 2);
     //echo $tax;
     $total = $price + $tax;
     //echo $total;
     // update the item as bought
     $item->bought = TRUE;
     $item->save();
     // update the transaction table for the user who buys the product
     $transactionBuy = new \App\Transaction();
     $transactionBuy->transaction_type = "BUY";
     $transactionBuy->public_item_id = $id;
     $transactionBuy->user_id = \Auth::id();
     $transactionBuy->tax = $tax;
     $transactionBuy->total = $total;
     $transactionBuy->save();
     //dump($transactionBuy->toArray());
     $transactionBuyObject = (object) $transactionBuy->toArray();
     $itemAsArray = $item->toArray();
     $itemObject = (object) $itemAsArray;
     // send an email to the user who made the purchase
     \Mail::send(['html' => 'pongo.sales_receipt_email'], array('item' => $itemObject, 'transactionBuy' => $transactionBuyObject), function ($message) {
         $message->to(\Auth::user()->email, \Auth::user()->name)->subject('You made a puchase on Pongo!');
     });
     // update the transaction table for user who sold the product
     $transactionSell = new \App\Transaction();
     $transactionSell->transaction_type = "SELL";
     $transactionSell->public_item_id = $id;
     $transactionSell->user_id = $user_id;
     $transactionSell->tax = $tax;
     $transactionSell->total = $total;
     $transactionSell->save();
     // delete the item from the added_items
     $addedItem = \App\AddedItem::where('one_line_description', '=', $item->one_line_description)->get();
     //dump($publicItem[0]);
     $addedItem[0]->delete();
     \Session::flash('flash_message', 'You successfully purchased the ' . $itemObject->item . '!');
     return view('pongo.receipt_details')->with(['item' => $itemObject, 'transactionBuy' => $transactionBuyObject]);
 }
Beispiel #3
0
 /**
  * Responds to requests to
  */
 public function getPage($id = null)
 {
     //echo $id;
     // get the item
     $item = \App\PublicItem::where('id', '=', $id)->get();
     $itemAsArray = $item->toArray();
     //dump($itemAsArray[0]);
     $itemObject = (object) $itemAsArray[0];
     //dump($itemObject);
     return view('pongo.details')->with('item', $itemObject);
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     //
     $public_item_id = \App\PublicItem::where('item', '=', 'Coffee Mug')->pluck('id');
     DB::table('transactions')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'transaction_type' => 'BUY', 'public_item_id' => $public_item_id, 'user_id' => 1, 'tax' => 2.4, 'total' => 26.39]);
     $public_item_id = \App\PublicItem::where('item', '=', 'Coffee Mug')->pluck('id');
     DB::table('transactions')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'transaction_type' => 'SELL', 'public_item_id' => $public_item_id, 'user_id' => 3, 'tax' => 2.4, 'total' => 26.39]);
     $public_item_id = \App\PublicItem::where('item', '=', 'Binder')->pluck('id');
     DB::table('transactions')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'transaction_type' => 'BUY', 'public_item_id' => $public_item_id, 'user_id' => 2, 'tax' => 1.2, 'total' => 13.19]);
     $public_item_id = \App\PublicItem::where('item', '=', 'Binder')->pluck('id');
     DB::table('transactions')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'transaction_type' => 'SELL', 'public_item_id' => $public_item_id, 'user_id' => 4, 'tax' => 1.2, 'total' => 13.19]);
 }
 /**
  * Responds to requests to
  */
 public function getPage($id = null)
 {
     // find the item to delete
     $item = \App\AddedItem::find($id);
     //dump($item);
     $item->delete();
     //dump($item->make_public);
     // if it was made public, delete it from the public_items table
     if ($item->make_public) {
         $publicItem = \App\PublicItem::where('one_line_description', '=', $item->one_line_description)->get();
         //dump($publicItem[0]);
         $publicItem[0]->delete();
     }
     \Session::flash('flash_message', $item->item . ' was deleted.');
     return redirect('/myspace');
 }