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