I am using Laravel and I want to copy a Week table which I show below:
This is the code I am using:
// Aquí capturo el registro del día Lunes
$dia_lunes = Semana::where('codigo', 'T00040458')->where('dia', 'Lunes')->first();
// Aquí estoy recorriendo del siete al 20 porque esos son los nombres de las columnas.
// Estos números representan las horas del día.
for ($i = 7; $i <= 20; $i++) {
// Aquí estoy actualizando la tabla Perturbada con la información de la tabla Semana.
Perturbada::where('codigo', 'T00040458')->where('dia', 'Lunes')->update([$i => $dia_lunes->$i]);
}
// De aquí en adelante repito lo mismo para los demás días.
$dia_martes = Semana::where('codigo', 'T00040458')->where('dia', 'Martes')->first();
for ($i = 7; $i <= 20; $i++) {
Perturbada::where('codigo', 'T00040458')->where('dia', 'Martes')->update([$i => $dia_martes->$i]);
}
$dia_miercoles = Semana::where('codigo', 'T00040458')->where('dia', 'Miercoles')->first();
for ($i = 7; $i <= 20; $i++) {
Perturbada::where('codigo', 'T00040458')->where('dia', 'Miercoles')->update([$i => $dia_miercoles->$i]);
}
$dia_jueves = Semana::where('codigo', 'T00040458')->where('dia', 'Jueves')->first();
for ($i = 7; $i <= 20; $i++) {
Perturbada::where('codigo', 'T00040458')->where('dia', 'Jueves')->update([$i => $dia_jueves->$i]);
}
$dia_viernes = Semana::where('codigo', 'T00040458')->where('dia', 'Viernes')->first();
for ($i = 7; $i <= 20; $i++) {
Perturbada::where('codigo', 'T00040458')->where('dia', 'Viernes')->update([$i => $dia_viernes->$i]);
}
$dia_sabado = Semana::where('codigo', 'T00040458')->where('dia', 'Sabado')->first();
for ($i = 7; $i <= 20; $i++) {
Perturbada::where('codigo', 'T00040458')->where('dia', 'Sabado')->update([$i => $dia_sabado->$i]);
}
dd();
The problem I have is that nothing is being copied to the other table and I think the reason for this is because the names of the columns are numbers, since if, for example, I do:
- day_monday->8
- day_monday->'8'
- day_monday->{8}
- day_monday->{'8'}
If I try to use these variables I get null or it gives me an error. This is the code and finally an image of the error. I hope you can help me. Thanks in advance.
$dia_lunes = Semana::where('codigo', 'T00040458')->where('dia', 'Lunes')->first();
dd($dia_lunes->8);