public function postStore() { $redirect_url = 'admin/orders/create'; $validation = $this->validateStoreInputs(Input::all()); if ($validation->fails()) { return redirect($redirect_url)->withErrors($validation)->withInput(); } $transaction_id = Input::get('transaction_id'); $payment_status = Input::get('payment_status'); $paid = Input::get('paid'); $email = Input::get('email'); // Check user first $user = User::where('email', $email)->first(); if ($user == null) { // No such user $errors = new \Illuminate\Support\MessageBag(); $errors->add('userError', "The user may have been deleted. Please try again."); return redirect($redirect_url)->withErrors($errors)->withInput(); } $apply_to_models = array(); // Save products to order $selected_products = Input::get('selected_products'); $apply_to_models = array_merge($apply_to_models, $this->addModelToArray($selected_products, new Product())); // Save bundles to order $selected_bundles = Input::get('selected_bundles'); $apply_to_models = array_merge($apply_to_models, $this->addModelToArray($selected_bundles, new Bundle())); // Save pricelists to order $pricelists = Input::get('pricelist_id'); $apply_to_models = array_merge($apply_to_models, $this->addModelToArraySimpleMode($pricelists, new Pricelist())); // No product/bundle to add if (count($apply_to_models) == 0) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('productError', "The items selected may have been deleted. Please try again."); return redirect($redirect_url)->withErrors($errors)->withInput(); } $new_order = new Order(); $new_order->user_id = $user->id; $new_order->paid = $paid; $new_order->transaction_id = $transaction_id; $new_order->payment_status = $payment_status; $new_order->save(); // Save the products/bundles foreach ($apply_to_models as $apply_to_model) { $apply_to_model->orders()->save($new_order); } // Save coupons to order $coupons = Input::get('coupon_id'); $errors = $this->addCouponToOrder($coupons, $new_order); if ($errors) { return redirect($this->pageRoute)->withErrors($errors); } return redirect($this->pageRoute); }
public function postStore() { $sid = \Input::get('id'); $rules = array('pricelist_id' => 'required|integer', 'transaction_id' => 'required', 'payment_status' => 'required', 'paid' => 'numeric', 'email' => 'required|email'); $validation = \Validator::make(\Input::all(), $rules); $redirect_url = isset($sid) ? 'admin/purchases/edit/' . $sid : 'admin/purchases/create'; if ($validation->fails()) { return redirect($redirect_url)->withErrors($validation)->withInput(); } $pricelist_id = \Input::get('pricelist_id'); $transaction_id = \Input::get('transaction_id'); $payment_status = \Input::get('payment_status'); $paid = \Input::get('paid'); $email = \Input::get('email'); $pricelist = Pricelist::find($pricelist_id); // No such pricelist if ($pricelist == null) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('pricelistError', "The Module/Membership may have been deleted. Please try again."); return redirect($redirect_url)->withErrors($errors)->withInput(); } $user = User::where('email', $email)->first(); if ($user == null) { // No such user $errors = new \Illuminate\Support\MessageBag(); $errors->add('userError', "The user may have been deleted. Please try again."); return redirect($redirect_url)->withErrors($errors)->withInput(); } // Check if user_pricelist already exist $existing = UserPricelist::join('order_pricelist', 'orders.id', '=', 'order_pricelist.id')->where('orders.user_id', $user->id)->where('order_pricelist.pricelist_id', $pricelist->id)->count(); if ($existing > 0) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('userpricelistError', $email . " has already purchased " . $pricelist->module->name . " (" . $pricelist->membership->name . ")."); return redirect($redirect_url)->withErrors($errors)->withInput(); } $new_purchase = new UserPricelist(); $new_purchase->user_id = $user->id; $new_purchase->pricelist_id = $pricelist->id; $new_purchase->paid = $paid; $new_purchase->transaction_id = $transaction_id; $new_purchase->payment_status = $payment_status; $new_purchase->save(); return redirect('admin/purchases'); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { if ($this->auth->guest()) { if ($request->ajax()) { return view('redminportal::users.notauthorized'); } else { return redirect()->guest('login'); } } $email = Auth::user()->email; // Check if user is in Admin group $user = User::where('email', $email)->first(); if ($user != null) { $group = $user->groups()->where('name', 'Admin')->first(); if ($group != null) { // Save login time $user->last_login = date('Y-m-d H:i:s'); $user->save(); return $next($request); } } return redirect('login/unauthorized'); }