Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

307
Visualizações
Laravel - How to resolve auto-increment skipping id one step at a point in Cron jobs

I have a Laravel-5.8 project that runs cron job schedule

public function handle()
{       
    $client = new Client();
    $res = $client->request('GET','https://api.employees.net/allemployees', [
       'query' => ['key' => 'dfffgggggffffff']
   ])->getBody();

    $clientdatas = json_decode($res->getContents(), true);        

    foreach($clientdatas as $clientdata)
    {         
        Employee::updateOrCreate([
            'employee_code' => $clientdata->staff_id,
        ],
        [
            'first_name'=> $clientdata->first_name,
            'last_name'=> $clientdata->flast_name,
            'other_name'=> $clientdata->middle_name,
        ]);  

        $user = User::updateOrCreate([
            'email'=> $employee->email,
        ],
        [
            'first_name'=> $employee->first_name,
            'last_name'=> $employee->last_name,
        ]);          

         $employee->update(['user_id' => $user->id]);            
    }           
}

The id for each model are auto-increment.

I observed that while the cron job was saving the external data from the api into the mysql database, the auto-increment for Employee model skipped a step at a point. It skipped 97 and moved to 99. However, the User model is okay, it didn't skip.

I observed that it skipped a particular on that the a particular field is empty:

 'last_name'                             => $employee->last_name,

That is last_name

employee table

mysql employee table

How do I resolve it?

Thank you.

over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda