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