php - 在 laravel 中的“存储”资源控制器之后立即显示视图
问题描述
所以目前我的“存储”资源控制器添加到我的数据库中的表并获取我的“索引”页面(我的主页)的视图但是当我刷新这个视图时,它会复制添加到数据库中的最后一行。我注意到 URI 是 ' http://127.0.0.1:8000/store ' 而不是 ' http://127.0.0.1:8000/index ' 有人可以解释一下发生了什么。对于缺乏技术术语,我深表歉意。我是一名新学徒,正在尝试使用自己的主动性来解决这个问题,但到目前为止还没有运气。我还注意到我的注销功能做了同样的事情,尽管 URI 略有不同,它仍然在 URI 中显示 CSRF 令牌,但它仍然在“注销”文件路径中显示它,这是一个示例;'http://127.0.0.1:8000/logout?_token=bqTl4J3EZyKj7LS5ZvqfRB8k1Qg02IT1j4WlBG51&dir2login= '
仅供参考,我已经尝试过 return $this->index();
我的注销控制器方法;
public function logout(){
Auth::logout();
return view('index',['posts'=>$this->getTable()]);
}
我的商店控制器方法:
public function store(Request $request){
//creates new row in database table
//$clientIp=$request->ip();
$post = new PostModel();
//gets email of user currently logged in
$post->email=Auth::user()->email;
$post->ip=$request->ip();
$post->content=$request->content;
$post->company=$request->company;
$post->rating=$request->rating;
//saves to database
$post->save();
return view('index',['posts'=>$this->getTable()]);
}
解决方案
你有没有尝试过
返回重定向('/');
推荐阅读
- javascript - 从输入文本中删除的只是数字的值与我的简单数组不匹配
- python - 如何根据另一个小部件的位置放置小部件?
- javascript - 将所有 JS 代码和变量视为执行上下文的属性是否正确?
- python - 平均 groupby 取决于两列
- sql - 如何规范化具有多值字段的表?
- r - 滚动连接在data.table中生效时如何标记
- c# - 在不使用锁的情况下原子地更改两个数字
- python - ?: (urls.W005) URL 命名空间 'main' 不是唯一的。您可能无法反转此命名空间中的所有 URL
- react-native - 导入 expo-pixi 会导致 iOS 设备崩溃
- documentation - 向 Doxygen 添加自定义功能