gpt4 book ai didi

javascript - 在数据库中创建新位置后,直接重定向到新创建的 View

转载 作者:行者123 更新时间:2023-11-28 03:35:29 26 4
gpt4 key购买 nike

在我的网站上您可以创建协作者。我有一个带有表格的 Blade View ,您可以在其中看到所有内容。我希望在创建新协作者后返回新创建协作者的主视图。

我想我可以将它添加到我的javascript函数中,或者可能添加到路由函数中,而不是像return view('person.profile.profile-view')那样使用返回 ; 但我不知道如何从新创建的字段传递我需要的所有数据。

此外,我的协作者 View 需要大量数据,这是它的 Controller :

 public function profileView($id)
{
$person = $this->personRepository->getByIdWith($id, ['person_title', 'country', 'salutation']);
$practitioner_id = $this->practitionerRepository->getIdByPersonId($id);
$practitioner = $this->practitionerRepository->getById($practitioner_id);
$specialty_id = PractitionerSpecialty::where('practitioner_id', $practitioner_id)->value('specialty_id');

return view('person.profile.profile-view')
->with('person', $person)
->with('id', $id)
->with('person_titles', $this->personTitleRepository->getAll())
->with('countries', Country::all())
->with('specialties', Specialty::all())
->with('specialty', Specialty::where('specialty_id', $specialty_id)->value('name'))
->with('competence_levels', CompetenceLevel::all())
->with('salutations', PersonSalutation::all())
->with('practitioner', $practitioner)
->with('practitioner_specialty', PractitionerSpecialty::where('practitioner_id', $practitioner_id)->first())
->with('practitioner_competence_level', PractitionerCompetenceLevel::where('practitioner_id', $practitioner_id)->first());
}

我的 php 创建表单

<div class="modal fade crud-modal" id="create-Modal" tabindex="-1" role="dialog" style="z-index: 1050; display: none;"
aria-hidden="true">

[...]

<div class="modal-footer">
<button type="button" class="btn btn-default btn-round waves-effect "
data-dismiss="modal">{{trans('buttons.close')}}</button>
<button type="button" id="create_final_btn" class="btn btn-success btn-round"
>{{trans('buttons.add')}}</button>
</div>
</div>
</div>
</div>
var create = (function(){
var onSuccess;
var onHashSuccess;

var createButton = function(fieldValues, createUrl, required) {
$("#create_final_btn").click(function () {
forms.postObject(forms.readForm(fieldValues, '_create', undefined, required), createUrl, onSuccess);
});
};

[...]

var setOnSuccess = function(fun) {
onSuccess = fun;
};
var setOnHashSuccess = function(fun) {
onHashSuccess = fun;
};

return {
createButton: createButton,
createHashItemButton: createHashItemButton,
openCreateDialogButton: openCreateDialogButton,
setOnSuccess: setOnSuccess,
setOnHashSuccess: setOnHashSuccess,
openCreateTrainingPlanButton: openCreateTrainingPlanButton
};
}());

我在 route 的功能:

public function addPerson(Request $request) {
$this->validate($request, [
'data' => 'required',
'data.first_name' => 'required',
'data.last_name' => 'required',
'data.active' => 'required',
'data.person_salutation_id' => 'required',

]
);
$this->repository->create($request->all()['data']);
return back();
}

我认为最好的方法是在 javascript 函数中做到这一点。如果有人可以引导我找到最佳解决方案,那就太好了。

最佳答案

相反:

return back();

使用

$object = $this->repository->create($request->all()['data']);

return redirect()->route('routename', ['id' => $object->id]);

关于javascript - 在数据库中创建新位置后,直接重定向到新创建的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57785745/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com