repository = $payout; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Litecms\Payout\Repositories\Criteria\PayoutResourceCriteria::class); } /** * Display a list of payout. * * @return Response */ public function index(PayoutRequest $request) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\Litecms\Payout\Repositories\Presenter\PayoutPresenter::class) ->$function(); } $payouts = $this->repository->paginate(); return $this->response->title(trans('payout::payout.names')) ->view('payout::payout.index', true) ->data(compact('payouts')) ->output(); } /** * Display payout. * * @param Request $request * @param Model $payout * * @return Response */ public function show(PayoutRequest $request, Payout $payout) { if ($payout->exists) { $view = 'payout::payout.show'; } else { $view = 'payout::payout.new'; } return $this->response->title(trans('app.view') . ' ' . trans('payout::payout.name')) ->data(compact('payout')) ->view($view, true) ->output(); } /** * Show the form for creating a new payout. * * @param Request $request * * @return Response */ public function create(PayoutRequest $request) { $payout = $this->repository->newInstance([]); return $this->response->title(trans('app.new') . ' ' . trans('payout::payout.name')) ->view('payout::payout.create', true) ->data(compact('payout')) ->output(); } /** * Create new payout. * * @param Request $request * * @return Response */ public function store(PayoutRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $payout = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('payout::payout.name')])) ->code(204) ->status('success') ->url(guard_url('payout/payout/' . $payout->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/payout/payout')) ->redirect(); } } /** * Show payout for editing. * * @param Request $request * @param Model $payout * * @return Response */ public function edit(PayoutRequest $request, Payout $payout) { return $this->response->title(trans('app.edit') . ' ' . trans('payout::payout.name')) ->view('payout::payout.edit', true) ->data(compact('payout')) ->output(); } /** * Update the payout. * * @param Request $request * @param Model $payout * * @return Response */ public function update(PayoutRequest $request, Payout $payout) { try { $attributes = $request->all(); $payout->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('payout::payout.name')])) ->code(204) ->status('success') ->url(guard_url('payout/payout/' . $payout->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('payout/payout/' . $payout->getRouteKey())) ->redirect(); } } /** * Remove the payout. * * @param Model $payout * * @return Response */ public function destroy(PayoutRequest $request, Payout $payout) { try { $payout->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('payout::payout.name')])) ->code(202) ->status('success') ->url(guard_url('payout/payout/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('payout/payout/' . $payout->getRouteKey())) ->redirect(); } } /** * Remove multiple payout. * * @param Model $payout * * @return Response */ public function delete(PayoutRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('payout::payout.name')])) ->status("success") ->code(202) ->url(guard_url('payout/payout')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/payout/payout')) ->redirect(); } } /** * Restore deleted payouts. * * @param Model $payout * * @return Response */ public function restore(PayoutRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('payout::payout.name')])) ->status("success") ->code(202) ->url(guard_url('/payout/payout')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/payout/payout/')) ->redirect(); } } }