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) { return $this->repository ->setPresenter(\Bixo\Parser\Repositories\Presenter\ParserPresenter::class) ->paginate(); } /** * Display parser. * * @param Request $request * @param Model $parser * * @return Response */ public function show(ParserRequest $request, Parser $parser) { return $parser->setPresenter(\Bixo\Parser\Repositories\Presenter\ParserListPresenter::class); ; } /** * Create new parser. * * @param Request $request * * @return Response */ public function store(ParserRequest $request) { try { $data = $request->all(); $data['user_id'] = user_id(); $data['user_type'] = user_type(); $data = $this->repository->create($data); $message = trans('messages.success.created', ['Module' => trans('parser::parser.name')]); $code = 204; $status = 'success'; $url = guard_url('parser/parser/' . $parser->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('parser/parser'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the parser. * * @param Request $request * @param Model $parser * * @return Response */ public function update(ParserRequest $request, Parser $parser) { try { $data = $request->all(); $parser->update($data); $message = trans('messages.success.updated', ['Module' => trans('parser::parser.name')]); $code = 204; $status = 'success'; $url = guard_url('parser/parser/' . $parser->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('parser/parser/' . $parser->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the parser. * * @param Model $parser * * @return Response */ public function destroy(ParserRequest $request, Parser $parser) { try { $parser->delete(); $message = trans('messages.success.deleted', ['Module' => trans('parser::parser.name')]); $code = 202; $status = 'success'; $url = guard_url('parser/parser/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('parser/parser/' . $parser->getRouteKey()); } return compact('message', 'code', 'status', 'url'); } /** * Return the form elements as json. * * @param String $element * * @return json */ public function form($element = 'fields') { $form = new Form(); return $form->form($element, true); } }