I have one form which user can submit and update previously stored data in database column. Is just simple input field which can take string.
I want to make it that if user come back after a day or an hour and submit new value on the form to save it in column separated with comma from previous one.
This is the form
{{ Form::open() }}
{{ Form::text('value', '', ['class' => 'form-control', 'id' => 'value', 'autocomplete' => 'off']) }}
<button type="submit" class="btn btn-primary">Submit</button>
{{ Form::close() }}
And I've tried to use implode()
in my controller to do this but instead of add second submit it's delete previous one and insert the new one.
$value=implode(",",(array)Input::get('value'));
$user->user_value = $value;
$user->save();
It's seems pretty simple yet I can't figured it out. Can anyone help me?
Note: User can submit one value at the time.
You are overwriting the value every time you submit the form. You should concatenate the old value to the new one before saving. Like so:
if (empty($user->user_value))
$user->user_value = \Input::get('value');
else
$user->user_value = $user->user_value . ',' . \Input::get('value');
$user->save();
One solution would be to retrieve the current value from the database, merge the new value(from the form) with the current as strings and then save the merged value.