I’m trying to insert selected checkbox value into my database but I don’t seem to know how because I’m new to laravel.
This is the foreach code:
@foreach($users as $user)
<?php $id +=1; ?>
<ul class="list-group">
<div class="card">
<li class="list-group-item group-containers">
<div class="row">
<input type="checkbox" value="{{ $user->name }}" onclick="checkBox(this)" class="form-check-input" type="checkbox" id="approver"
value="{{ $user->name }}">
<div class="col-1 c-avatar mr-3">
<img class="c-avatar-img" src="{{ url('/assets/img/avatars/3.png') }}">
</div>
<div class="col-8">
<div class="">{{ $user->name }}</div>
<label for="" class="text-secondary">{{ $user->email }}</label>
</div>
</div>
</li>
</div>
</ul>
@endforeach
Here is my checkbox code:
<div class="card-body scroll" style="background-color: #F2F2F2">
<div id="listUser"></div>
<ol class="list-group" style="display:none">
<div class="card">
<li class="list-group-item">
<div class="row">
<div class="col-1 c-avatar mr-3">
<img class="c-avatar-img" src="{{ url('/assets/img/avatars/3.png') }}">
</div>
<div class="col-8">
<div class="">{{ $users[0]->name }}</div>
</div>
</div>
</li>
</div>
</ol>
</div>
And my javascript code:
function checkBox(cb) {
var inners = '<ol id="'+ cb.value +'" class="list-group">' +
'<div class="card">' +
'<li class="list-group-item">' +
'<div class="row">' +
'<div class="col-1 c-avatar mr-3">' +
'<img class="c-avatar-img" src="{{ url('/assets/img/avatars/3.png') }}">' +
'</div>' +
'<div class="col-8">' +
'<div class="">' + cb.value + '</div>' +
'</div>' +
'</li>' +
'</div>' +
'</ol>';
console.log(cb.value);
if (cb.checked == true) {
//text.style.display = 'block';
document.getElementById('listUser').innerHTML += inners;
} else {
// text.style.display = 'none';
document.getElementById(cb.value).remove();
}
}
The data I’m trying to insert is the name and email. Is there any solutions?