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