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