repository = $body; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Lavalite\Auto\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\Auto\Repositories\Presenter\BodyPresenter::class) ->$function(); } $bodies = $this->repository->paginate(); return $this->response->title(trans('auto::body.names')) ->view('auto::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 = 'auto::body.show'; } else { $view = 'auto::body.new'; } return $this->response->title(trans('app.view') . ' ' . trans('auto::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('auto::body.name')) ->view('auto::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('auto::body.name')])) ->code(204) ->status('success') ->url(guard_url('auto/body/' . $body->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/auto/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('auto::body.name')) ->view('auto::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('auto::body.name')])) ->code(204) ->status('success') ->url(guard_url('auto/body/' . $body->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('auto/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('auto::body.name')])) ->code(202) ->status('success') ->url(guard_url('auto/body/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('auto/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('auto::body.name')])) ->status("success") ->code(202) ->url(guard_url('auto/body')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/auto/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('auto::body.name')])) ->status("success") ->code(202) ->url(guard_url('/auto/body')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/auto/body/')) ->redirect(); } } }