How to create a cycle that allows inserting hours with differences of every 15 minutes in the database?

0

I am using full calendar and php to fill it with events, I recive a form that I made a date and a start time and an end time, what I want to do is program it so that if I set as the initial time 8:00 am and end time 1:00 pm for example I do believe that 20 insert to the database, with the same information but with a difference of 15 minutes in the hour the first would be from 8 to 8:15 and the second from 8: 15 to 8:30 and so on. but I do not succeed, if it's my code

 public function create_event(Request $request){
    $input= $request->all();
    $minutosA=15;
    $segundosInicio=strtotime($input["hora_inicio"]);
    $segundos_añadir=$minutosA*60;
    $horaFin=date("H:i",$segundosInicio+$segundos_añadir);
    $horaInicio=$input["hora_inicio"];
    $input["idEspecialista"]="2";
    $input["descripcion"]="este es un evento de prueba";
    $input["color"]="#FD1C02";
    $input["inicio"]=$input["inicio"]." ".$horaInicio;
    $input["fin"]=$input["fin"]." ".$input["hora_fin"];
    calendar::create($input);
    return redirect()->route('calendar');
}

If someone knows how to program the cycle, it would be very helpful.

    
asked by Harvey66 11.12.2018 в 17:39
source

1 answer

0

To manipulate dates and times in Laravel it is advisable to use Carbon , your code would be as follows:

$horaInicio = Carbon::createFromFormat('H:i', $input["hora_inicio"]);

for ( $i=0;$i<20;$i++ )
{
    $horaFin = $horaInicio -> addMinutes(15);

    $input["idEspecialista"] = "2";
    $input["descripcion"]    = "este es un evento de prueba";
    $input["color"]          = "#FD1C02";
    $input["inicio"]         = $horaInicio;
    $input["fin"]            = $hora_fin;
    calendar::create($input);
    return redirect()->route('calendar');

    $horaInicio = $horaFin;
}
    
answered by 11.12.2018 / 20:31
source