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