首页 > 解决方案 > 在 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()]);
}

标签: phphtmllaravelurlhomestead

解决方案


你有没有尝试过

返回重定向('/');


推荐阅读