This week i've decided to move from CodeIgniter to Laravel. Atm I'm trying to "migrate" my old CI website over to Laravel.
Note: I am very new to Laravel, so if there's something that I'm doing wrong then please say :) I am used to CodeIgniter, I don't even know if this will work in Laravel.
Here is how i want it to be / as i had it in codeigniter --> http://pastebin.com/DRaW0Mzt
public function add()
{
$data['header'] = "Create New User";
$data['title'] = "Create New User";
$data['description'] = "Create New User";
$data['user_groups'] = UserGroup::all();
return View::make('users.create', $data);
}
function create()
{
$validator = Validator::make(
array(
'email' => Input::get('email'),
'username' => Input::get('username'),
),
array(
'email' => 'required|email|unique:users',
'username' => 'required|min:3|max:14|unique:users',
)
);
if ($validator->fails())
{
/* If there's an error then just call the add function again */
/* $validator->messages(); should still be available since it is still the same "instance" */
/* This is how i did it on CodeIgniter */
$this->add();
}else{
/* success code... */
}
}
If $validator fails i want it to call $this->add(); again. Note: i have tried doing the following;
return Redirect::to('users/add')->withInput()->withErrors($validator); # redirect to users/add, WITH the old input and WITH the errors from $validator. */
Problem #1: When calling $this->add(); it call the function, but it doesn't execute the code inside the function, the view is not created and all $data is not passed to the view.
And also, IF i create;
protected $layout = "layouts.master";
It will use that one instead of;
return View::make('users.create', $data);
But no $data will be passed to it.
Problem #2: The problem with using Redirect::to(); is that IF the user reloads the page then all Input::old(); is gone since withInput() and withErrors(); uses session to store the data and it only lasts for one request, also the errors go away. including the CSS around/on the inputs https://dl.dropboxusercontent.com/u/11204765/SS/SS-026.png
Note: I tried using both the following;
Session::reflash();
Session::keep(array(...));
Anyone knows a solution to the problem? or what I'm possibly doing wrong?
Any help is appreciated!
Redirect::toorRedirect::back(). #2 Why is it a problem? If use reloads the page, then it should be reloaded, ain't it?Redirect::to()->withInput->()->withErrors();then 1) i won't be able to dl.dropboxusercontent.com/u/11204765/SS/SS-026.png get CSS around my Inputs without tons of if statements in my view files. 2) if the user reloads the page (for whatever reason) all the old input is gone, and so are the errors, because->withInput();and->withErros();utilize session, which means the data only lasts 1 request and i want it to last several requests if neccessary, which is why i also tried to useSession::reflash();andSession::keep();