forked from eatvio/eatvio-infra
45 lines
945 B
PHP
45 lines
945 B
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\Recipe;
|
|
use Illuminate\Console\Command;
|
|
|
|
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();
|
|
}
|
|
);
|
|
}
|
|
}
|