public function addOffer(request $request) { $validator = Validator::make($request->all(), ['store_id' => 'required', 'title' => 'required|max:255', 'startDate' => 'required|date', 'endDate' => 'required|date', 'fineprint' => 'required|min:5']); $input = $request->only('store_id'); if ($validator->fails()) { return redirect('admin/store/' . $input["store_id"] . '/addoffer')->withErrors($validator); } $offer = Offers::create($request->only('store_id', 'title', 'fineprint', 'startDate', 'endDate')); return redirect('admin/store/' . $input['store_id'] . '/offers/all'); }
public function addOffer(request $request) { $rules = array('store_id' => 'required', 'title' => 'required', 'fineprint' => 'required', 'startDate' => 'required', 'endDate' => 'required'); $Validator = $this->customValidator($request->all(), $rules, array()); if ($Validator->fails()) { return response()->json(['response_code' => 'ERR_RULES', 'messages' => $Validator->errors()->all()], 400); } $store_id = $request->only('store_id'); if (!$this->checkUserHasStore($store_id['store_id'], true)) { return response()->json(['response_code' => 'ERR_UNA', 'messages' => 'User Not Authorized'], 403); } $offer = Offers::create($request->only('store_id', 'title', 'fineprint', 'startDate', 'endDate')); return response()->json(['response_code' => 'RES_SOC', 'messages' => 'Store Offer Created', 'data' => $offer], 201); }
public function addOffer(request $request) { $rules = array('title' => 'required', 'fineprint' => 'required', 'startDate' => 'required', 'endDate' => 'required'); $Validator = $this->customValidator($request->all(), $rules, array()); if ($Validator->fails()) { return response()->json(['response_code' => 'ERR_RULES', 'messages' => $Validator->errors()->all()], 400); } $is_parent = false; $offerArr = $request->only('title', 'fineprint'); $offerArr['startDate'] = date('Y-m-d H:i:s', strtotime($request->input('startDate'))); $offerArr['endDate'] = date('Y-m-d H:i:s', strtotime($request->input('endDate'))); if ($request->has('store_token')) { if ($request->input('store_token') == 'all' && Auth::user()->Stores->is_parent) { $store_id = Auth::user()->Stores->id; $is_parent = true; } else { if ($request->input('store_token') == 'all') { return response()->json(['response_code' => 'ERR_UNA', 'messages' => 'User Not Authorized'], 403); } else { $storeId = Crypt::decrypt($request->input('store_token')); if (!$this->checkUserHasStorePermission($storeId)) { return response()->json(['response_code' => 'ERR_UNA', 'messages' => 'User Not Authorized'], 403); } $store_id = $storeId; } } } else { $store_id = Auth::user()->Stores->id; } $offerArr['store_id'] = $store_id; $offer = Offers::create($offerArr); if ($is_parent) { //creating offer for all sub merchants if user selects and if he is super merchant $offer->is_parent = true; $offer->save(); $matchThese = ['is_child' => true, 'parent_id' => $store_id]; $stores = MerchantStore::where($matchThese)->get(); $offerInp = $request->only('title', 'fineprint', 'startDate', 'endDate'); $offerInp['is_child'] = true; $offerInp['parent_id'] = $offer->id; foreach ($stores as $store) { $offerInp['store_id'] = $store->id; Offers::create($offerInp); } } return response()->json(['response_code' => 'RES_SOC', 'messages' => 'Store Offer Created', 'data' => $offer], 201); }
public function addOffer(request $request) { $rules = array('title' => 'required', 'fineprint' => 'required', 'startDate' => 'required', 'endDate' => 'required'); $validator = $this->customValidator($request->all(), $rules, array()); if ($validator->fails()) { return response()->json(['status' => 'fail', 'message' => $validator->errors()->all()]); } $is_parent = false; $fineprintArr = explode("\n", $request->input('fineprint')); $fineprint = ''; foreach ($fineprintArr as $value) { if ($value != '' || !empty($value)) { $fineprint .= '<li>' . $value . '</li>'; } } if ($request->has('store_token')) { if ($request->input('store_token') == 'all' && Auth::user()->Stores->is_parent) { $store_id = Auth::user()->Stores->id; $is_parent = true; } else { if ($request->input('store_token') == 'all') { return response()->json(['status' => 'fail', 'message' => 'Not Authorized']); } else { $storeId = Crypt::decrypt($request->input('store_token')); if (!$this->checkUserHasStorePermission($storeId)) { return response()->json(['status' => 'fail', 'message' => 'Not Authorized']); } $store_id = $storeId; } } } else { $store_id = Auth::user()->Stores->id; } $offerInput = $request->only('title', 'startDate', 'endDate'); $offerInput['store_id'] = $store_id; $offerInput['fineprint'] = $fineprint; $offer = Offers::create($offerInput); if ($is_parent) { $offer->is_parent = true; $offer->save(); //creating offer for all sub merchants if user selects and if he is super merchant $matchThese = ['is_child' => true, 'parent_id' => $store_id]; $stores = MerchantStore::where($matchThese)->get(); $offerInp = $request->only('title', 'fineprint', 'startDate', 'endDate'); $offerInp['is_child'] = true; $offerInp['parent_id'] = $offer->id; foreach ($stores as $store) { $offerInp['store_id'] = $store->id; Offers::create($offerInp); } } return response()->json(['status' => 'success']); }