/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { $items = $request->get('items'); $me = \Auth::user(); $order = new \App\Order(); $order->client()->associate($me); $my_orders = $me->orders; if ($my_orders->isEmpty()) { foreach ($me->waiters()->online()->get() as $waiter) { \App\Notification::add($me->toArray(), 'serve_me', $waiter); } } else { $my_order = $my_orders->first()->toArray(); if ($my_order['waiter_id']) { $waiter = \App\User::find($my_order['waiter_id']); $order->waiter()->associate($waiter); \App\Notification::add($me->toArray(), 'serve_me_again', $waiter); } } $order->save(); foreach ($items as $item) { $food = \App\Food::find($item['food']); if ($food->category->menu->admin_id == $me->admin_id) { $item = new \App\OrderItem($item); $item->food()->associate($food); $item->order()->associate($order); $item->save(); } } return $order->load('items.food'); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $order = new \App\Order($request->all()); $cart = $request->session()->get('cart', function () { return null; }); if ($cart == null) { return redirect('cart'); } DB::transaction(function () use($order, $cart) { $order->save(); $total = 0; foreach ($cart as $id => $qty) { if ($qty <= 0) { continue; } $pro = \App\Product::find($id); $od = new \App\OrderDetail(); $od->price = $pro->price; $od->quantity = $qty; $od->product()->associate($pro); $od->order()->associate($order); $od->save(); $total += $qty * $pro->price; } if ($total > 0) { $order->status = 1; //???????????? $order->total = $total; $order->update(); } }); $request->session()->forget('cart'); return redirect('order'); }
/** * Run the database seeds. * * @return void */ public function run() { $datapetname = ['max', 'cody', 'nala', 'diego']; for ($i = 0; $i < count($datapetname); ++$i) { $order = new \App\Order(); $order->pet_name = $datapetname[$i]; $order->user_id = 1; $order->save(); } }
/** * Run the database seeds. * * @return void */ public function run() { DB::table('orders')->truncate(); $sweeties = App\Sweety::all(); $orders = [[$sweeties->random(), $sweeties->random()], [$sweeties->random(), $sweeties->random()], [$sweeties->random(), $sweeties->random()], [$sweeties->random(), $sweeties->random()], [$sweeties->random(), $sweeties->random()]]; foreach ($orders as $order) { $newOrder = new App\Order(); $newOrder->setTotal($order[0]->price + $order[1]->price); $newOrder->save(); foreach ($order as $sweety) { $newOrder->sweeties()->attach(App\Sweety::findOrFail($sweety->id)); } $newOrder->save(); } }
function storeOrder() { $input = Input::all(); $validate = Validator::make(Input::all(), ['manufacturer_id' => 'required', 'dealer_id' => 'required']); if (!$validate->fails()) { $dealer = DB::table('dealers')->where('id', Input::get('dealer_id'))->first(); $manufacturer = DB::table('manufacturers')->where('id', Input::get('manufacturer_id'))->first(); $order = new \App\Order(); $order->user_id = Auth::user()->id; $order->dealer_id = Input::get('dealer_id'); $order->manufacturer_id = Input::get('manufacturer_id'); $order->name = ""; $order->dealer_name = $dealer->name; $order->manufacturer_name = $manufacturer->name; $order->description = ""; if ($order->save()) { $order_id = $order->id; $order = \App\Order::find($order_id); $order->name = "OrdNo-" . $order_id; $order->save(); $items = array(); $product_names = Input::get("prod_name"); $qtys = Input::get("prod_qty"); $remarks = Input::get("prod_remark"); for ($i = 0; $i < 25; $i++) { if (isset($product_names[$i])) { $product = \App\Product::where('id', $product_names[$i])->first(); $mrp = 0; $item_qty = 0; $total_price = 0; if ($product) { $mrp = $product->max_retail_price; $item_qty = $qtys[$i]; $total_price = $mrp * $item_qty; $items[] = ['order_id' => $order_id, 'product_id' => $product->id, 'name' => $product->name, 'quantity' => $item_qty, 'price' => $total_price, 'remarks' => $remarks[$i]]; } } } //dd($items); DB::table('items')->insert($items); return redirect("users/orders")->with('success', 'Order added successfully!'); } else { return Redirect::back()->withInput()->withErrors("Unable to create order."); } } else { return Redirect::back()->withInput()->with('error', 'You need to select Manufacturer and Dealer')->withErrors($validate); } }
public function index() { $orders = App\Order::all(); foreach ($orders as $order) { $customer = App\Customer::find($order->customer_id); echo $order->name . " Ordered by " . $order->customer->name . "<br/>"; } }
public function run() { // Uncomment the below to wipe the table clean before populating DB::table('orders')->delete(); for ($i = 0; $i < 100; $i++) { App\Order::create(['customer_id' => rand(1, 100)]); } }
/** * Responds to requests to POST /orders/create */ public function postCreate(Request $request) { $this->validate($request, ['pet_name' => 'required|min:2', 'treats' => 'required_without:accesories', 'accesories' => 'required_without:treats']); # Enter order into the database $order = new \App\Order(); $order->pet_name = $request->pet_name; #$book->author_id = $request->author; $order->user_id = \Auth::id(); # <--- NEW LINE #$order->quantity = $request->quantity; $order->save(); # Add the accessories if ($request->accesories) { $accesories = $request->accesories; } else { $accesories = []; } $order->accesory()->sync($accesories); #$ordertreat = new \App\Order(); #$ordertreat->pet_name = $request->pet_name; #$book->author_id = $request->author; #$ordertreat->user_id = \Auth::id(); # <--- NEW LINE #$order->quantity = $request->quantity; #$ordertreat->save(); # Add the treats if ($request->treats) { $treats = $request->treats; } else { $treats = []; } $order->treat()->sync($treats); # Done \Session::flash('flash_message', 'Your order was added!'); return redirect('/orders'); }
public function complete(Request $request) { $carts = \App\Cart::whereUserId($this->user()->id)->get(); if (!count($carts)) { return redirect(route('home.index')); } $payuResponse = ""; $order = new \App\Order(); $order->user_id = $this->user()->id; $order->date_time = date('Y-m-d H:i:s'); $order->save(); try { //documentación //http://developers.payulatam.com/es/api/sandbox.html //https://github.com/mauricio067/integracion-payu-php require_once '../resources/libs/payu/PayU.php'; //URL de Pagos \Environment::setPaymentsCustomUrl("https://stg.api.payulatam.com/payments-api/4.0/service.cgi"); \PayU::$apiKey = "6u39nqhq8ftd0hlvnjfs66eh8c"; \PayU::$apiLogin = "******"; \PayU::$merchantId = "500238"; \PayU::$language = \SupportedLanguages::ES; \PayU::$isTest = true; //Parámetros básicos de pago $prefix = env('APP_ENV') == 'production' ? 'PED' : 'TEST'; $parameters = array(\PayUParameters::REFERENCE_CODE => $prefix . str_pad($order->id, 10, '0', STR_PAD_LEFT), \PayUParameters::COUNTRY => \PayUCountries::PE, \PayUParameters::ACCOUNT_ID => "500546", \PayUParameters::CURRENCY => "USD", \PayUParameters::DESCRIPTION => $this->user()->cart_description, \PayUParameters::VALUE => $this->user()->total_cart_amount); //Datos tarjeta de crédito $parameters[\PayUParameters::INSTALLMENTS_NUMBER] = 1; //Número de cuotas $parameters[\PayUParameters::PAYER_NAME] = $request->get('name', ''); //$this->user()->name; $parameters[\PayUParameters::CREDIT_CARD_NUMBER] = $request->get('number', ''); $parameters[\PayUParameters::CREDIT_CARD_EXPIRATION_DATE] = $request->get('expiration', ''); $parameters[\PayUParameters::CREDIT_CARD_SECURITY_CODE] = $request->get('cvv', ''); $parameters[\PayUParameters::PROCESS_WITHOUT_CVV2] = false; $parameters[\PayUParameters::PAYMENT_METHOD] = 'VISA'; $payuResponse = \PayUPayments::doAuthorizationAndCapture($parameters); if (isset($payuResponse->code) && $payuResponse->code == 'SUCCESS') { if (isset($payuResponse->transactionResponse->state) && $payuResponse->transactionResponse->state == 'APPROVED') { if ($this->generateTickets($order, $payuResponse)) { \Mail::queue('email.order', ['order' => $order], function ($message) use($order) { $message->to($order->user->email); }); return redirect(route('user.orders')); } } else { $order->data = json_encode($payuResponse); $order->status = 'error'; $order->save(); return redirect(route('checkout.error'))->with('order', $order); } } else { $order->data = json_encode($payuResponse); $order->status = 'error'; $order->save(); return redirect(route('checkout.error'))->with('order', $order); } } catch (\Exception $ex) { $order->data = $ex->getMessage(); $order->status = 'error'; $order->save(); return redirect(route('checkout.error'))->with('order', $order); } }
#dd( \Gloudemans\Shoppingcart\Facades\Cart::content()); # dd(\Illuminate\Support\Facades\Session::all()); #\Illuminate\Support\Facades\Session::flush(); #dd(Cache::pull('order1')) #dd(\Illuminate\Support\Facades\Cache::get('user')); ?> {!!\Collective\Html\FormFacade::open(['file='=>true,'action'=>'TestController@test'])!!} {{--{!!\Collective\Html\FormFacade::file('image')!!}--}} {{--<input type="text" name="name" value=""/>--}} {{--<input type="text" name="role_id" value=""/>--}} {{--<input type="checkbox" name="cb"/>--}} <script src='https://www.google.com/recaptcha/api.js'></script> <div class="g-recaptcha" data-sitekey="6LdkCQoTAAAAALNT3hXvjB3fQXX9Rc1_zmyd4LyF"></div> <input type="submit" value="go"/> {!!\Collective\Html\FormFacade::close()!!} {{--</pre>--}} {{--@include('layout.frontend.head')--}} <?php $c = new \App\Artist(); $c->update(['talent' => 11]); $order = new \App\Order(); $t = $order->with('deliveryDetailOfCustomer')->where('id', 50)->get()->toArray(); dd($t); $cus = new \App\Customer(); $t = $cus->with('user')->get()->toArray(); dd(); ?> #$cd->render() {{--@include('layout.frontend.footer')--}}
<?php error_reporting(E_ALL); ini_set('display_errors', 1); require_once "vendor/autoload.php"; $list = [["from" => "Stockholm", "to" => "New York", "type" => "flight", "info" => ["number" => "SK22", "gate" => "22", "seat" => "7B", "baggage" => "automatically transferred from your last leg"]], ["from" => "Barcelona", "to" => "Gerona", "type" => "airport bus", "info" => ["seat" => ""]], ["from" => "Gerona", "to" => "Stockholm", "type" => "flight", "info" => ["number" => "SK455", "gate" => "45B", "seat" => "3A", "baggage" => "ticket counter 344"]], ["from" => "Madrid", "to" => "Barcelona", "type" => "train", "info" => ["number" => "78A", "seat" => "45B"]]]; $l = App\Order::this()->cardsList($list); echo App\textGenerator::htmlGenerate($l);