【发布时间】:2017-01-14 03:04:10
【问题描述】:
使用 Laravel 5.2
我试图将会话数据存储在控制器中,然后如果验证成功,我想将用户重定向到下一页。当我执行 Redirct::to('nextpage') 时,会话数据会在我的下一页和控制器中丢失。
这是从 'domainSearch' 获取表单 post 值的控制器
class domainSearch extends Controller
{
public function store(Request $request)
{
// validate the info, create rules for the inputs
$rules = array(
'domainSearch' => 'required' // make sure the username field is not empty
);
// run the validation rules on the inputs from the form
$validator = Validator::make(Input::all(), $rules);
// if the validator fails, redirect back to the form
if ($validator->fails()) {
return Redirect::to('/')
->withErrors($validator) // send back all errors to the login form
->withInput(Input::except('password')); // send back the input (not the password) so that we can repopulate the form
}
else {
// validation not successful, send back to form
$request->session()->put('domainname', $request->get('domainSearch'));
return Redirect::to('/domainlist');
}
}
}
这是我试图将会话数据传递给并获取的控制器。但它始终保持为空。
class DomainList extends Controller
{
public function index(Request $request){
var_dump($request->get('domainname'));
return view('domainlist');
}
}
如果我用 return view('view') 将用户发送到下一页;会话数据在那里,但在使用重定向功能时被清除。
如何在不丢失会话数据和变量的情况下进行重定向?
【问题讨论】:
-
您使用
$request->session()->put但随后使用$request->get。您可能需要使用$request->session()->get -
优秀.. :) 非常感谢!
标签: php laravel redirect laravel-5 frameworks