form = ProfileForm::grouped(false) ->setAttributes() ->toArray(); $this->modules = $this->modules(config('litecms.profile.modules'), 'profile', guard_url('profile')); } /** * Display a list of profile. * * @return Response */ public function index(ProfileResourceRequest $request) { $pageLimit = $request->input('pageLimit', config('database.pagination.limit')); $page = Profile::pushScope(new RequestScope()) ->pushScope(new ProfileResourceScope()) ->paginate($pageLimit); $data = new ProfilesCollection($page); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('profile::profile.names')) ->view('profile::profile.index') ->data(compact('data', 'modules', 'form')) ->output(); } /** * Display profile. * * @param Request $request * @param Model $profile * * @return Response */ public function show(ProfileResourceRequest $request, Profile $model) { $form = $this->form; $modules = $this->modules; $data = new ProfileResource($model); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('profile::profile.name')) ->data(compact('data', 'form', 'modules')) ->view('profile::profile.show') ->output(); } /** * Show the form for creating a new profile. * * @param Request $request * * @return Response */ public function create(ProfileResourceRequest $request, Profile $model) { $form = $this->form; $modules = $this->modules; $data = new ProfileResource($model); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('profile::profile.name')) ->view('profile::profile.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new profile. * * @param Request $request * * @return Response */ public function store(ProfileResourceRequest $request, Profile $model) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $model = $model->create($attributes); $data = new ProfileResource($model); return $this->response->message(trans('messages.success.created', ['Module' => trans('profile::profile.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('profile/profile/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/profile/profile')) ->redirect(); } } /** * Show profile for editing. * * @param Request $request * @param Model $profile * * @return Response */ public function edit(ProfileResourceRequest $request, Profile $model) { $form = $this->form; $modules = $this->modules; $data = new ProfileResource($model); // return view('profile::profile.edit', compact('data', 'form', 'modules')); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('profile::profile.name')) ->view('profile::profile.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the profile. * * @param Request $request * @param Model $profile * * @return Response */ public function update(ProfileResourceRequest $request, Profile $model) { try { $attributes = $request->all(); $model->update($attributes); $data = new ProfileResource($model); return $this->response->message(trans('messages.success.updated', ['Module' => trans('profile::profile.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('profile/profile/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('profile/profile/' . $model->getRouteKey())) ->redirect(); } } /** * Remove the profile. * * @param Model $profile * * @return Response */ public function destroy(ProfileResourceRequest $request, Profile $model) { try { $model->delete(); $data = new ProfileResource($model); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('profile::profile.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('profile/profile/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('profile/profile/' . $model->getRouteKey())) ->redirect(); } } }