repository = $leads; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Bixo\Lead\Repositories\Criteria\LeadsResourceCriteria::class); } /** * Display a list of leads. * * @return Response */ public function index(LeadsRequest $request) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\Bixo\Lead\Repositories\Presenter\LeadsPresenter::class) ->$function(); } $leads = $this->repository->paginate(); return $this->response->setMetaTitle(trans('lead::leads.names')) ->view('lead::leads.index', true) ->data(compact('leads', 'view')) ->output(); } /** * Display leads. * * @param Request $request * @param Model $leads * * @return Response */ public function show(LeadsRequest $request, Leads $leads) { if ($leads->exists) { $view = 'lead::leads.show'; } else { $view = 'lead::leads.new'; } return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('lead::leads.name')) ->data(compact('leads')) ->view($view, true) ->output(); } /** * Show the form for creating a new leads. * * @param Request $request * * @return Response */ public function create(LeadsRequest $request) { $leads = $this->repository->newInstance([]); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('lead::leads.name')) ->view('lead::leads.create', true) ->data(compact('leads')) ->output(); } /** * Create new leads. * * @param Request $request * * @return Response */ public function store(LeadsRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $leads = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('lead::leads.name')])) ->code(204) ->status('success') ->url(guard_url('lead/leads/' . $leads->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/lead/leads')) ->redirect(); } } /** * Show leads for editing. * * @param Request $request * @param Model $leads * * @return Response */ public function edit(LeadsRequest $request, Leads $leads) { return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('lead::leads.name')) ->view('lead::leads.edit', true) ->data(compact('leads')) ->output(); } /** * Update the leads. * * @param Request $request * @param Model $leads * * @return Response */ public function update(LeadsRequest $request, Leads $leads) { try { $attributes = $request->all(); $leads->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('lead::leads.name')])) ->code(204) ->status('success') ->url(guard_url('lead/leads/' . $leads->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('lead/leads/' . $leads->getRouteKey())) ->redirect(); } } /** * Remove the leads. * * @param Model $leads * * @return Response */ public function destroy(LeadsRequest $request, Leads $leads) { try { $leads->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('lead::leads.name')])) ->code(202) ->status('success') ->url(guard_url('lead/leads/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('lead/leads/' . $leads->getRouteKey())) ->redirect(); } } /** * Remove multiple leads. * * @param Model $leads * * @return Response */ public function delete(LeadsRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('lead::leads.name')])) ->status("success") ->code(202) ->url(guard_url('lead/leads')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/lead/leads')) ->redirect(); } } /** * Restore deleted leads. * * @param Model $leads * * @return Response */ public function restore(LeadsRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('lead::leads.name')])) ->status("success") ->code(202) ->url(guard_url('/lead/leads')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/lead/leads/')) ->redirect(); } } }