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