所以此刻我的“商店”资源控制器添加到表在我的数据库并获取查看我的“索引”页面(我的主页),但是当我刷新该视图复制添加到数据库中的最后一行。我已经注意到了这个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='
FYI我已经尝试返回$这个 - >指数();
我的注销控制器的方法;
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()]);
}
你有没有尝试过
返回重定向( '/');
什么你想在这里做的就是让用户在索引视图。然而,而不是返回不同的视图(和具有“帖子”再次定义的逻辑),它更容易将用户重定向到控制器的索引方法。你有多种选择这样做。我有三个如下:
这是您目前有:
return view('index',['posts'=>$this->getTable()]);\
你可以做的“动作”(ControllerName @ FunctionName):
return redirect()->action('PostController@index');
或用“命名的路线”:
return redirect()->route('posts.index');
或直接URL
return redirect('/');