I have a loop that generates rows of data. If I use chrome developer tool, I can see that each row has a unique value for data-host-id. However, when I click on any of the records, it always updates the very first record. It's not honoring the record I would like to update.
Note: I'm not looking to delete multiple records at the same time, I just want to delete the appropriate record via its associated button.
Snippet of HTML code
<input data-size="mini" type="checkbox" class="switch-api"
data-on-text="Yes" data-off-text="No" id="api_id" data-host-id="{{ $k }}" checked>
snippet of JS code
$(".switch-api").bootstrapSwitch();
$('.switch-api').on('switchChange.bootstrapSwitch', function (event, state) {
if (state) {
$.ajax({
url: '/dashboard/'+ $('#api_id').attr('data-host-id') + '/toggleapicheck',
data: { api_id: $('#api_id').attr('data-host-id'), state:'true'},
Controller
public function toggleapicheck(Request $request)
{
$api_id = $request->input('api_id');
$state = $request->input('state');
$dashboard = new Dashboard();
$dashboard->toggleApicheck($api_id, $state);
}
Model
function toggleApicheck($api_id, $state)
{
$sf = new \SensioLabs\Consul\ServiceFactory(array('base_url' => "http://127.0.0.1:8500"));
$kv = $sf->get('kv');
$kv->put('apichecks/'.$api_id.'/enable',$state);
}