validate([ 'memo' => 'sometimes|string|max:191', 'code' => 'required|string|alpha_dash|max:36', 'uses' => 'required|numeric|max:2147483647', 'credits' => 'required|numeric|between:0,99999999', 'expires_at' => 'required|date|after:today', ]); Voucher::create($request->except('_token')); return redirect()->route('admin.vouchers.index')->with('success', 'voucher has been created!'); } /** * Display the specified resource. * * @param Voucher $voucher * @return Response */ public function show(Voucher $voucher) { // } /** * Show the form for editing the specified resource. * * @param Voucher $voucher * @return Response */ public function edit(Voucher $voucher) { // } /** * Update the specified resource in storage. * * @param Request $request * @param Voucher $voucher * @return Response */ public function update(Request $request, Voucher $voucher) { // } /** * Remove the specified resource from storage. * * @param Voucher $voucher * @return RedirectResponse */ public function destroy(Voucher $voucher) { $voucher->delete(); return redirect()->back()->with('success', 'voucher has been removed!'); } public function dataTable() { $query = Voucher::with(['users']); return datatables($query) ->addColumn('actions', function (Voucher $voucher) { return '
' . csrf_field() . ' ' . method_field("DELETE") . '
'; }) ->addColumn('status', function (Voucher $voucher) { $color = 'success'; if ($voucher->getStatus() != 'VALID') $color = 'danger'; return ''. $voucher->getStatus() .''; }) ->editColumn('uses', function (Voucher $voucher) { $userCount = $voucher->users()->count(); return "{$userCount} / {$voucher->uses}"; }) ->editColumn('credits', function (Voucher $voucher) { return number_format($voucher->credits, 2, '.', ''); }) ->editColumn('expires_at', function (Voucher $voucher) { return $voucher->expires_at ? $voucher->expires_at->diffForHumans() : ''; }) ->editColumn('code' , function (Voucher $voucher) { return "{$voucher->code}"; }) ->rawColumns(['actions' , 'code' , 'status']) ->make(); } }