Gotcha - Using 'name' as a form name field stopped old() from working as expected. edit - I'm an idiot. Something else was messing with the "name" values.
I ran in circles with this for a long time so thought I'd document it here in case it saves anyone else an hour of hair-pulling.
Controller has the line
public function store(Request $request)
{
request()->session()->flash('info', "Name:" . request()->name . " Foo:" . request()->foo);
return back()->withInput();
}
Form is
<form class="form" action="/blocks" method="POST">
@csrf
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">
Add Email Blocks
</button>
</div>
</div>
<div class="form-group">
<label for="foo">foo</label>
<input type="text" name="foo" id="foo" class="form-control" value="{{ old('foo') }}">
</div>
<div class="form-group">
<label for="name">Name</label>
<input type="text" name="name" id="name" class="form-control" value="{{ old('name') }}">
</div>
</form>
Submitting the form the "name" field was never updated, but foo would be.
Thought i'd submit this here as Laracasts ranks highly for Laravel issues so this might help someone in the future.
@liamvictor that does not make sense. Just tested your code in my project and it works as expected.. Make sure you don't have a problem with the session for some reason.
Test in a different browser.
Do you use file as a SESSION_DRIVER?
Or having a JavaScript that clears the value for this field as well.
You're right, something else is fiddling with the name field. I did it in another project and it worked as expected.
Sorry for any confusion I cause others! Unfortunately there doesn't seem to be a delete to get rid of my erroneous message.
Please sign in or create an account to participate in this conversation.