@vincent15000 public $bono = []. I don't know why the variable change the type. I added some dump() to see how the code works and when mark the bonus with id 10, the code work fine, so I mark the bonus with id 4, but when I unmark the bonus with id 10, the bonus with id 4 get unmarked automatically and $bonus = [] turn boolean automatically too.
elseif ($renglon->renglon == '021') {
dump('inicio_renglon_no_vacio: ' . gettype($this->bono));
if (!empty($this->bono)) {
dump('inicio_bono_no_vacio: ' . gettype($this->bono));
dump($this->bono);
if (in_array(4, $this->bono) && in_array(10, $this->bono)) {
dump('validacion');
dump($this->bono);
$index = array_search(10, $this->bono);
dump('indice');
dump($index);
if ($index !== false) {
unset($this->bono[$index]);
dump('unset');
dump($this->bono);
}
dump('fin_doble_validacion: ' . gettype($this->bono));
}
dump('fin_validacion: ' . gettype($this->bono));
}
dump('fin_validacion: ' . gettype($this->bono));
if (is_array($this->bono)) {
$bonos = Bonificacion::select('bono', 'cantidad')->whereIn('id', $this->bono)->get();
}
dump('otro: ' . gettype($this->bono));
if (!empty($bonos)) {
foreach ($bonos as $bono) {
if ($bono->bono == 'Bono profesional' || $bono->bono == 'Bono de antigüedad') {
$this->aguinaldo += number_format($bono->cantidad, 2, '.', '');
}
}
}
dump('otro: ' . gettype($this->bono));
}
dump() with bonus id=10 checked
"inicio_renglon_no_vacio: array" // app\Livewire\Puesto\Puestos.php:275
"inicio_bono_no_vacio: array" // app\Livewire\Puesto\Puestos.php:277
array:1 [▼ // app\Livewire\Puesto\Puestos.php:278
0 => "10"
]
"fin_validacion: array" // app\Livewire\Puesto\Puestos.php:293
"fin_validacion: array" // app\Livewire\Puesto\Puestos.php:295
"otro: array" // app\Livewire\Puesto\Puestos.php:299
"otro: array" // app\Livewire\Puesto\Puestos.php:307
dump() with bonus with id=10 and id=4 checked
"inicio_renglon_no_vacio: array" // app\Livewire\Puesto\Puestos.php:275
"inicio_bono_no_vacio: array" // app\Livewire\Puesto\Puestos.php:277
array:2 [▼ // app\Livewire\Puesto\Puestos.php:278
0 => "10"
1 => "4"
]
"validacion" // app\Livewire\Puesto\Puestos.php:280
array:2 [▼ // app\Livewire\Puesto\Puestos.php:281
0 => "10"
1 => "4"
]
"indice" // app\Livewire\Puesto\Puestos.php:284
0 // app\Livewire\Puesto\Puestos.php:285
"unset" // app\Livewire\Puesto\Puestos.php:288
array:1 [▼ // app\Livewire\Puesto\Puestos.php:289
1 => "4"
]
"fin_doble_validacion: array" // app\Livewire\Puesto\Puestos.php:291
"fin_validacion: array" // app\Livewire\Puesto\Puestos.php:293
"fin_validacion: array" // app\Livewire\Puesto\Puestos.php:295
"otro: array" // app\Livewire\Puesto\Puestos.php:299
"otro: array" // app\Livewire\Puesto\Puestos.php:307
dump() with bonus id=10 unchecked and the id=4 will unchecked automatically too
"inicio_renglon_no_vacio: boolean" // app\Livewire\Puesto\Puestos.php:275
"inicio_bono_no_vacio: boolean" // app\Livewire\Puesto\Puestos.php:277
true // app\Livewire\Puesto\Puestos.php:278