laravel 5.7重定向到同一页面的部分ID [英] laravel 5.7 redirect to the same page to an section ID
问题描述
我是laravel的新手,找不到这个问题的任何线索.
I am new to laravel and couldn't find any clue to this issue.
我的页面结构如下
<section id="main">
</section>
<section id="about">
</section>
<section id="review">
</section>
<section id="contact">
@inc.messages
<form >
</form>
</section>
页面很长,验证失败错误存储在inc.message中,并且报告充分,但是页面返回到主视图"/",但我需要它返回ID为"/#contact"的部分,否则客户将无法读取错误.
the page is long, when the validations fails the errors are stored in inc.message and are well reported but the page goes back to the main view "/" but I need it to get back to the section with id "/#contact" as otherwise the customer won't be able to read the errors.
应该是这样的
if ($validator->fails())
{
return redirect()->route::view("/#contact")->withErrors($v->errors());
}
但是我以错误的方式使用视图,因为我找不到将重定向路由到"/#contact"的方式.
but I am using view in the wrong way as I can't find a way to route the redirection to "/#contact".
是否可以在控制器中进行选择或触发js方法?
Is it possible to get on the selection or trig a js method within the controller?
好的,我使用laravel文档解决了:修改的方法是提交",而这些修改是:
ok I solved using the laravel documentations: the method modified is "submit" and those are the modifications:
$validator = Validator::make($request->all(), [
'name'=>'required',
'phone'=>'required|numeric|digits_between:8,15',
'email'=>'required|email',
]);
if ($validator->fails()) {
return redirect()->to('/'.'#contact')
->withErrors($validator)
->withInput();
}
我添加了使用验证器";
and I added "use Validator;"
谢谢大家
推荐答案
可以尝试
return redirect()->to('/link address'.'/#contact')
or return redirect(route('name'.'/#contact'))
这篇关于laravel 5.7重定向到同一页面的部分ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!