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