To accomplish that, you'll first need some JavaScript. As an example, have a look at this fiddle.
HTML:
<p>Users</p>
<ul id="users-list">
<li><input type="text" name="names[]" value="" placeholder="enter name" /></li>
</ul>
<button id="add-more">Add More Users</button>
JS (using jQuery):
$(document).ready(function() {
$users_list = $('#users-list');
$add_more = $('#add-more');
$add_more.on('click', function() {
$users_list.find('li:first').clone().find(':input').val('').end().appendTo($users_list);
});
});
Don't pay much attention to the actual code (it doesn't even include a form or a submit button, it's just a rough example); mostly focus on the logic so you can adapt it for your needs.
After you submit your form, the "names" input will be an array of strings instead of a single string (as it would be without the []).
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community