Currently, I am trying to use Form Request and seperate the logic to validate out of controller. The down side is that the documentation is unclear on how I should pass states back to the controller when the validation instance fails and I am redirected back. I am trying to temporarily store an image inside the server, so the saved image would be displayed back to the user when they fail the validations.
Here is a part of my controller:
protected function session_data(Request $request, $id = null)
{
// process $data
return $data;
}
//view model of edit page
public function edit(Request $request, $id)
{
if ($request->session()->has('_old_input')) {
$data = $this->session_data($request, $id);
} else { // get session data if exists, or search the db.
$data = Seminar::index_list($id)[0];
}
return view('exhibitor.seminar.edit')
->with('entry', $data);
}
// logic to handle post request from edit page
public function update(SeminarEditRequest $request) //validate post request
{
return 'stub';
}
A user will make a put
request to update
. If the validation fails, it will redirect back towards the edit
method.
By default, the implementation of _old_input
session key which contains information about previous form data wouldn't contain information about the uploaded file when a user makes a post/put request to update
method and fails the rules defined in SeminarEditRequest
. My question is how can I pass (and store) information about uploaded files inside SeminarEditRequest.php
?