I have created input elements using javascript, looks like this:
...
for(var i = 1; i<slider.value; i++) {
+'<div class=\"input-group\">'
+'<input id=\"input-chapter-start'+i+'\" type=\"text\">'
+'</div>'
}
Now I am trying to get these dynamic created input ids in my model.
My Model looks like this so far.
protected $fillable = ['email', 'title', 'filename'];
My problem is now how to properly get the ids in the array.
I could not run something like this.
protected $fillable = [
'email',
'title',
'filename',
for ($i=0; $i < ; $i++) {
# code...
}
];
EDIT:
My Model looks like this now:
protected $fillable = ['email', 'title', 'filename', 'input-chapter-start', 'input-chapter-end'];
In my Controller I get them like this:
$chapterStartTime = Input::get('input-chapter-start');
$chapterEndTime = Input::get('input-chapter-end');
dd($chapterStartTime);
Returns
null
laravel can't get input value by id, you have to make input name input-chapter-start[]
should look like this:
<input type="text" name="input-chapter-start[]">
note, []
brackets mean that this input gets multiple values and it is array so you can make loop in your controller and get value of each input-chapter-start
I think you have to add input element this way in js :
for(var i = 1; i<slider.value; i++) {
+'<div class=\"input-group\">'
+'<input name="did['+id+']" value="'+id+'" id=\"input-chapter-start'+i+'\" type=\"text\">'
+'</div>'
}
And you can get dynamic array in controller or model like this way:
Input::get('did');
You can try...