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