62 lines
1.3 KiB
PHP
62 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use App\Models\Shop\Family;
|
|
use App\Models\Shop\Genre;
|
|
|
|
class migrate extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'create_relation';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Migration from old version';
|
|
|
|
/**
|
|
* Create a new command instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function handle()
|
|
{
|
|
$genres = Genre::all();
|
|
foreach ($genres as $genre) {
|
|
$family_name = $genre->family;
|
|
dump($family_name);
|
|
if (!empty($family_name)) {
|
|
$family = Family::byName($family_name)->first();
|
|
if (isset($family->name))
|
|
{
|
|
dump($family->name);
|
|
$genre->family_id = $family->id;
|
|
$genre->save();
|
|
} else {
|
|
dump("non trouvé");
|
|
}
|
|
} else {
|
|
dump("Aucune famille");
|
|
}
|
|
}
|
|
}
|
|
}
|