如何在 Laravel 中保存数据后重定向回上一页?
How to redirect back to the previous page after saving data in Laravel?
我是 laravel 的新手。
我正在创建这个项目,在这里,在我保存数据后,我想 return 到我以前的状态。
public function storeData(Request $request){
// dd($request->all());
$this->validate($request,[
'Province'=>'required',
'District' => 'required|max:100|min:3',
'Electrorate' => 'required|max:100|min:3',
'PollingBooth' => 'required|max:100|min:3',
'issueTitle' => 'required|max:160|min:3',
'issueDetails'=>'required|max:500|min:30',
'issueCategory'=>'required'
]);
$pollingbooth = new pollingbooth;
$pollingbooth->Province=$request->Province;
$pollingbooth->District=$request->District;
$pollingbooth->Electrorate=$request->Electrorate;
$pollingbooth->PollingBooth=$request->PollingBooth;
$pollingbooth->issueTitle=$request->issueTitle;
$pollingbooth->issueDetails=$request->issueDetails;
$pollingbooth->issueCategory=$request->issueCategory;
$pollingbooth->save();
$pollingBoothNames=pollingbooth::all();
// dd ($pollingBoothNames);
return view('issues')->with('pollingBoothNamez',$pollingBoothNames);
// return redirect()->back();
}
以上是我的代码。我试过了
return view('issues')->with('pollingBoothNamez',$pollingBoothNames)->redirect()->back();
但运气不好。我应该在这里做什么?
我在更新“问题”时也遇到了同样的问题。
您可以简单地像这样调用路由 return redirect('home/dashboard');
return redirect()->back();
或
return Redirect::to('your-route-url');
这会起作用:
return redirect()->back()->with(''pollingBoothNamez', $pollingBoothNames);
我是 laravel 的新手。 我正在创建这个项目,在这里,在我保存数据后,我想 return 到我以前的状态。
public function storeData(Request $request){
// dd($request->all());
$this->validate($request,[
'Province'=>'required',
'District' => 'required|max:100|min:3',
'Electrorate' => 'required|max:100|min:3',
'PollingBooth' => 'required|max:100|min:3',
'issueTitle' => 'required|max:160|min:3',
'issueDetails'=>'required|max:500|min:30',
'issueCategory'=>'required'
]);
$pollingbooth = new pollingbooth;
$pollingbooth->Province=$request->Province;
$pollingbooth->District=$request->District;
$pollingbooth->Electrorate=$request->Electrorate;
$pollingbooth->PollingBooth=$request->PollingBooth;
$pollingbooth->issueTitle=$request->issueTitle;
$pollingbooth->issueDetails=$request->issueDetails;
$pollingbooth->issueCategory=$request->issueCategory;
$pollingbooth->save();
$pollingBoothNames=pollingbooth::all();
// dd ($pollingBoothNames);
return view('issues')->with('pollingBoothNamez',$pollingBoothNames);
// return redirect()->back();
}
以上是我的代码。我试过了
return view('issues')->with('pollingBoothNamez',$pollingBoothNames)->redirect()->back();
但运气不好。我应该在这里做什么? 我在更新“问题”时也遇到了同样的问题。
您可以简单地像这样调用路由 return redirect('home/dashboard');
return redirect()->back();
或
return Redirect::to('your-route-url');
这会起作用:
return redirect()->back()->with(''pollingBoothNamez', $pollingBoothNames);