Using Laravel 5.2
Im trying to store session data in controller, then if validation succeed, i want to redirect the user to next page. When i do the Redirct::to('nextpage') the session data is lost in my next page and controller.
This is the controller in getting the form post value from 'domainSearch'
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');
}
}
}
This is the controller im trying to pass session data to and pick up. But it always remain null.
class DomainList extends Controller
{
public function index(Request $request){
var_dump($request->get('domainname'));
return view('domainlist');
}
}
If i send the user to next page with return view('view'); the session data is there, but get cleared out when using the redirect function.
How to i redirect without losing session data and variables?