I want to return back request data into fields if validation fails on create action. I've created resource controller and there is pre-set functions (index, create, store, show, edit, update, destroy).
In example, in the Edit controller I already have an ID of a record, then I can just select record from DB by it's ID and pass it's data to the view, so that I will able to see entry data in fields on page load:
<input name="name" value="{{ $name }}" />
public function edit($id)
{
$item = Item::find($id);
return view('pages.item.edit')->with($data);
}
But in the Create controller I do not have any ID of item to fetch and pass entry data for fields.
<input name="name" value="{{ old('name') }}" />
public function store(Request $request)
{
$this->validate($request, [
'name' => 'required|string|max:30'
])->withInput();
return redirect('/items')->with('success', 'New item created!');
}
Should I use ->withInput() and where? {{ old('name') }} doesn't work too.
This and this articles didn't help me
So, how to save fields if validation fails? For Edit method it will be also useful to save modified fields.
$request->flash();then retrieve it later after validationsession('field_name')