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