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