repository = $deal; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Boomee\Deal\Repositories\Criteria\DealResourceCriteria::class); } /** * Display a list of deal. * * @return Response */ public function index(DealRequest $request) { return $this->repository ->setPresenter(\Boomee\Deal\Repositories\Presenter\DealPresenter::class) ->paginate(); } /** * Display deal. * * @param Request $request * @param Model $deal * * @return Response */ public function show(DealRequest $request, Deal $deal) { return $deal->setPresenter(\Boomee\Deal\Repositories\Presenter\DealListPresenter::class); ; } /** * Create new deal. * * @param Request $request * * @return Response */ public function store(DealRequest $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('deal::deal.name')]); $code = 204; $status = 'success'; $url = guard_url('deal/deal/' . $deal->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('deal/deal'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the deal. * * @param Request $request * @param Model $deal * * @return Response */ public function update(DealRequest $request, Deal $deal) { try { $data = $request->all(); $deal->update($data); $message = trans('messages.success.updated', ['Module' => trans('deal::deal.name')]); $code = 204; $status = 'success'; $url = guard_url('deal/deal/' . $deal->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('deal/deal/' . $deal->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the deal. * * @param Model $deal * * @return Response */ public function destroy(DealRequest $request, Deal $deal) { try { $deal->delete(); $message = trans('messages.success.deleted', ['Module' => trans('deal::deal.name')]); $code = 202; $status = 'success'; $url = guard_url('deal/deal/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('deal/deal/' . $deal->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); } }