improve validation style of starts_from and ends_till in CartRuleRepository
This commit is contained in:
parent
d4876d0148
commit
75d22eaf3a
|
|
@ -10,7 +10,7 @@ use Webkul\CartRule\Repositories\CartRuleCouponRepository;
|
|||
/**
|
||||
* Cart Rule controller
|
||||
*
|
||||
* @author Jitendra Singh <jitendra@webkul.com>
|
||||
* @author Jitendra Singh <jitendra@webkul.com>
|
||||
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||
*/
|
||||
class CartRuleController extends Controller
|
||||
|
|
@ -39,8 +39,9 @@ class CartRuleController extends Controller
|
|||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @param \Webkul\CartRule\Repositories\CartRuleRepository $cartRuleRepository
|
||||
* @param \Webkul\CartRule\Repositories\CartRuleCouponRepository $cartRuleCouponRepository
|
||||
* @param \Webkul\CartRule\Repositories\CartRuleRepository $cartRuleRepository
|
||||
* @param \Webkul\CartRule\Repositories\CartRuleCouponRepository $cartRuleCouponRepository
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(
|
||||
|
|
@ -83,16 +84,16 @@ class CartRuleController extends Controller
|
|||
public function store()
|
||||
{
|
||||
$this->validate(request(), [
|
||||
'name' => 'required',
|
||||
'channels' => 'required|array|min:1',
|
||||
'customer_groups' => 'required|array|min:1',
|
||||
'coupon_type' => 'required',
|
||||
'name' => 'required',
|
||||
'channels' => 'required|array|min:1',
|
||||
'customer_groups' => 'required|array|min:1',
|
||||
'coupon_type' => 'required',
|
||||
'use_auto_generation' => 'required_if:coupon_type,==,1',
|
||||
'coupon_code' => 'required_if:use_auto_generation,==,0',
|
||||
'starts_from' => 'nullable|date',
|
||||
'ends_till' => 'nullable|date|after_or_equal:starts_from',
|
||||
'action_type' => 'required',
|
||||
'discount_amount' => 'required|numeric'
|
||||
'coupon_code' => 'required_if:use_auto_generation,==,0',
|
||||
'starts_from' => 'nullable|date',
|
||||
'ends_till' => 'nullable|date|after_or_equal:starts_from',
|
||||
'action_type' => 'required',
|
||||
'discount_amount' => 'required|numeric',
|
||||
]);
|
||||
|
||||
$data = request()->all();
|
||||
|
|
@ -112,6 +113,7 @@ class CartRuleController extends Controller
|
|||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
|
|
@ -124,23 +126,24 @@ class CartRuleController extends Controller
|
|||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$this->validate(request(), [
|
||||
'name' => 'required',
|
||||
'channels' => 'required|array|min:1',
|
||||
'customer_groups' => 'required|array|min:1',
|
||||
'coupon_type' => 'required',
|
||||
'name' => 'required',
|
||||
'channels' => 'required|array|min:1',
|
||||
'customer_groups' => 'required|array|min:1',
|
||||
'coupon_type' => 'required',
|
||||
'use_auto_generation' => 'required_if:coupon_type,==,1',
|
||||
'coupon_code' => 'required_if:use_auto_generation,==,0',
|
||||
'starts_from' => 'nullable|date',
|
||||
'ends_till' => 'nullable|date|after_or_equal:starts_from',
|
||||
'action_type' => 'required',
|
||||
'discount_amount' => 'required|numeric'
|
||||
'coupon_code' => 'required_if:use_auto_generation,==,0',
|
||||
'starts_from' => 'nullable|date',
|
||||
'ends_till' => 'nullable|date|after_or_equal:starts_from',
|
||||
'action_type' => 'required',
|
||||
'discount_amount' => 'required|numeric',
|
||||
]);
|
||||
|
||||
$cartRule = $this->cartRuleRepository->findOrFail($id);
|
||||
|
|
@ -159,7 +162,8 @@ class CartRuleController extends Controller
|
|||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @param int $id
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
|
|
@ -176,7 +180,7 @@ class CartRuleController extends Controller
|
|||
session()->flash('success', trans('admin::app.response.delete-success', ['name' => 'Cart Rule']));
|
||||
|
||||
return response()->json(['message' => true], 200);
|
||||
} catch(\Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
session()->flash('error', trans('admin::app.response.delete-failed', ['name' => 'Cart Rule']));
|
||||
}
|
||||
|
||||
|
|
@ -191,9 +195,9 @@ class CartRuleController extends Controller
|
|||
public function generateCoupons()
|
||||
{
|
||||
$this->validate(request(), [
|
||||
'coupon_qty' => 'required|integer|min:1',
|
||||
'coupon_qty' => 'required|integer|min:1',
|
||||
'code_length' => 'required|integer|min:10',
|
||||
'code_format' => 'required'
|
||||
'code_format' => 'required',
|
||||
]);
|
||||
|
||||
if (! request('id'))
|
||||
|
|
|
|||
|
|
@ -125,9 +125,9 @@ class CartRuleRepository extends Repository
|
|||
*/
|
||||
public function create(array $data)
|
||||
{
|
||||
$data['starts_from'] = $data['starts_from'] ?: null;
|
||||
$data['starts_from'] = isset($data['starts_from']) ? $data['starts_from'] : null;
|
||||
|
||||
$data['ends_till'] = $data['ends_till'] ?: null;
|
||||
$data['ends_till'] = isset($data['ends_till']) ? $data['ends_till'] : null;
|
||||
|
||||
$data['status'] = ! isset($data['status']) ? 0 : 1;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue