英文:
How can I remove hash from form action URL in Laravel?
问题
我有一个带有动作的表单
action="/users#addUserModal"
当表单中存在错误时,在重定向后,Bootstrap 模态框会自动打开。但当没有错误时,模态框仍然显示。
$data = $request->safe()->only(['first_name', 'last_name', 'birth_date', 'username', 'is_admin', 'password']);
$user = User::create($data);
if ($user->exists) {
session()->flash("success", "User saved");
return redirect('admin');
}
return back()->with('error', 'User not saved');
如何使重定向到 admin 页面而不带有井号?
英文:
I have form with action
action="/users#addUserModal"
When there is errors in form, after redirect bootstrap modal will open automatically. but when no errors modal is still shown.
$data = $request->safe()->only(['first_name', 'last_name', 'birth_date', 'username', 'is_admin', 'password']);
$user = User::create($data);
if ($user->exists) {
session()->flash("success", "User saved");
return redirect('admin');
}
return back()->with('error', 'User not saved');
how to make this redirect to admin without hashtag?
答案1
得分: 2
protected function getRedirectUrl()
{
return parent::getRedirectUrl() . '#addUserModal';
}
我通过将此代码添加到请求类中修复了它。
英文:
protected function getRedirectUrl()
{
return parent::getRedirectUrl() . '#addUserModal';
}
i fixed it by adding this to request class.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论