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