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) { return $this->repository ->setPresenter(\Autos\Dealer\Repositories\Presenter\DealerPresenter::class) ->paginate(); } /** * Display dealer. * * @param Request $request * @param Model $dealer * * @return Response */ public function show(DealerRequest $request, Dealer $dealer) { return $dealer->setPresenter(\Autos\Dealer\Repositories\Presenter\DealerListPresenter::class); ; } /** * Create new dealer. * * @param Request $request * * @return Response */ public function store(DealerRequest $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('dealer::dealer.name')]); $code = 204; $status = 'success'; $url = guard_url('dealer/dealer/' . $dealer->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('dealer/dealer'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the dealer. * * @param Request $request * @param Model $dealer * * @return Response */ public function update(DealerRequest $request, Dealer $dealer) { try { $data = $request->all(); $dealer->update($data); $message = trans('messages.success.updated', ['Module' => trans('dealer::dealer.name')]); $code = 204; $status = 'success'; $url = guard_url('dealer/dealer/' . $dealer->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('dealer/dealer/' . $dealer->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the dealer. * * @param Model $dealer * * @return Response */ public function destroy(DealerRequest $request, Dealer $dealer) { try { $dealer->delete(); $message = trans('messages.success.deleted', ['Module' => trans('dealer::dealer.name')]); $code = 202; $status = 'success'; $url = guard_url('dealer/dealer/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('dealer/dealer/' . $dealer->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); } }