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