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

292
Visualizações
generate slug field for an existing data in database

i am using laravel and phpmyadmin and i need to add slug field for like 12K entries in my database .

i tried using a route to update the empty 'slug' column with slug data :

Route::get('/slug', function(){


$needSlugs = entreprise::where('slug', '')->get();

foreach($needSlugs as $slug){
    $slug->update([
        'slug' => Str::slug($slug->RS)
    ]);
}});

but it takes so much time and it returns an error after slugging about 400 columns and i need to start again and it will take me hours to finish, i searched a lot and didn't find a good solution for my case .

any good way to do it please !!

PS : i am using the sluggable-eloquent package to slug any new saved data in the DB .

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

12K rows is nothing. It usually should take only seconds to complete, there might be other reason why it doesn't completes Probably it's because gateway time out or other constraints on your server. Try running it using php artisan tinker, and also try to chunk your records.

$ php artisan tinker
App\Models\entreprise::where('slug', '')->chunk(500, function($recs){
  $recs->map(function($record){
    $record->update([
      'slug' => Str::slug($record->RS)
    ]);
  });
});
over 4 years ago · Santiago Trujillo Relatório

0

Try this.

$needSlugs = entreprise::whereNull('slug')->update(["slug"=> DB::raw("replace(trim(lower(RS)), ' ', '-')")]);

Note:Keep backup for safty purpose if its genuine data

over 4 years ago · Santiago Trujillo Relatório
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