This is the method I'm using to render my add project form. I solved the that generated the message Serialization of 'Closure' is not allowed
, but I don't really know what caused it. Changing the location of the $this->userInstance->all()
solved it. Removing the withInput($data)
also made it work, but then I wouldn't be able to send data with my redirect.
Question
So the error has been solved already, but what I want to know is why does the solution below works?
Correct version:
/*
* Add project.
*
**********************************************************************************************************/
public function addProject() {
/*
* When the user is not authorized for the page show unauthorized page.
*/
if(Atomend\Aeuser\AEUser::authorize('add-project') == false) {
return View::make("unauthorized");
}
/*
* Initialize the data array that gets send to the view.
*/
$data = [
"errors" => null
];
/*
* When the form is posted.
*/
if(Input::server("REQUEST_METHOD") == "POST") {
/*
* If the input is valid set the credentials.
*/
if($this->projectInstance->create()) {
/*
* Set the status message and set the status to true.
*/
$data["successes"] = $this->projectInstance->successes();
/*
* Redirect to the user overview on success.
*/
return Redirect::to("/projects")
->withInput($data);
} else {
/*
* Flash the input for usage in the view.
*/
Input::flash();
/*
* Set the data errors variable.
*/
$data["errors"] = $this->projectInstance->errors();
}
}
/*
* Get all users.
*/
$data["users"] = $this->userInstance->readAll();
return View::make("project-add", $data);
}
Error version:
/*
* Add project.
*
**********************************************************************************************************/
public function addProject() {
/*
* When the user is not authorized for the page show unauthorized page.
*/
if(Atomend\Aeuser\AEUser::authorize('add-project') == false) {
return View::make("unauthorized");
}
/*
* Initialize the data array that gets send to the view.
*/
$data = [
"errors" => null
];
/*
* Get all users.
*/
$data["users"] = $this->userInstance->readAll();
/*
* When the form is posted.
*/
if(Input::server("REQUEST_METHOD") == "POST") {
/*
* If the input is valid set the credentials.
*/
if($this->projectInstance->create()) {
/*
* Set the status message and set the status to true.
*/
$data["successes"] = $this->projectInstance->successes();
/*
* Redirect to the user overview on success.
*/
return Redirect::to("/projects")
->withInput($data);
} else {
/*
* Flash the input for usage in the view.
*/
Input::flash();
/*
* Set the data errors variable.
*/
$data["errors"] = $this->projectInstance->errors();
}
}
return View::make("project-add", $data);
}