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