Files
eatvio-infra/app/Console/Commands/UpdateSlugs.php
2023-12-26 12:15:09 +03:00

46 lines
912 B
PHP

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Models\Recipe;
class UpdateSlugs extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:update-slugs';
/**
* The console command description.
*
* @var string
*/
protected $description = 'update entities slugs';
/**
* Execute the console command.
*/
public function handle()
{
Recipe::where('slug', '')
->get()
->each(
function ($model) {
$newName = $model->title . " 2612";
$oldName = Str::replaceLast(' 2612', '', $newName);
$model->title = $newName;
$model->save();
$model->title = $oldName;
$model->save();
}
);
//
}
}