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