repository = $currency; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Inventory\Invent\Repositories\Criteria\CurrencyResourceCriteria::class); } /** * Display a list of currency. * * @return Response */ public function index(CurrencyRequest $request) { return $this->repository ->setPresenter(\Inventory\Invent\Repositories\Presenter\CurrencyPresenter::class) ->paginate(); } /** * Display currency. * * @param Request $request * @param Model $currency * * @return Response */ public function show(CurrencyRequest $request, Currency $currency) { return $currency->setPresenter(\Inventory\Invent\Repositories\Presenter\CurrencyListPresenter::class); ; } /** * Create new currency. * * @param Request $request * * @return Response */ public function store(CurrencyRequest $request) { try { $data = $request->all(); $data['user_id'] = user_id(); $data['user_type'] = user_type(); $data = $this->repository->create($data); $message = trans('messages.success.created', ['Module' => trans('invent::currency.name')]); $code = 204; $status = 'success'; $url = guard_url('invent/currency/' . $currency->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('invent/currency'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the currency. * * @param Request $request * @param Model $currency * * @return Response */ public function update(CurrencyRequest $request, Currency $currency) { try { $data = $request->all(); $currency->update($data); $message = trans('messages.success.updated', ['Module' => trans('invent::currency.name')]); $code = 204; $status = 'success'; $url = guard_url('invent/currency/' . $currency->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('invent/currency/' . $currency->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the currency. * * @param Model $currency * * @return Response */ public function destroy(CurrencyRequest $request, Currency $currency) { try { $currency->delete(); $message = trans('messages.success.deleted', ['Module' => trans('invent::currency.name')]); $code = 202; $status = 'success'; $url = guard_url('invent/currency/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('invent/currency/' . $currency->getRouteKey()); } return compact('message', 'code', 'status', 'url'); } /** * Return the form elements as json. * * @param String $element * * @return json */ public function form($element = 'fields') { $form = new Form(); return $form->form($element, true); } }