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