69 lines
2.1 KiB
PHP
69 lines
2.1 KiB
PHP
<?php
|
|
|
|
use App\Enums\Sections\PageSectionEnum;
|
|
use App\Lib\Helpers\FileStorageHelper;
|
|
use App\Models\Section;
|
|
use Illuminate\Database\Migrations\Migration;
|
|
use Illuminate\Support\Collection;
|
|
|
|
return new class extends Migration
|
|
{
|
|
/**
|
|
* Run the migrations.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function up(): void
|
|
{
|
|
Collection::macro('insertAfter', function ($target, $value, $new_key = null) {
|
|
if (is_int($target)) {
|
|
$this->items = array_merge(array_slice($this->items, 0, $target + 1), [$value], array_slice($this->items, $target + 1));
|
|
return;
|
|
}
|
|
|
|
foreach ($this->items as $key => $old) {
|
|
$new[$key] = $old;
|
|
if ($key === $target && is_null($new_key)) {
|
|
$new[] = $value;
|
|
} elseif ($key === $target) {
|
|
$new[$new_key] = $value;
|
|
}
|
|
}
|
|
|
|
$this->items = $new;
|
|
});
|
|
|
|
$quality = Section::query()->where('section', PageSectionEnum::produce_quality)->first();
|
|
if ($quality) {
|
|
$data = collect($quality->data);
|
|
$data->insertAfter(
|
|
'bloc_text_de_la_partie2_content',
|
|
collect(Section::emptyPictureBloc([], FileStorageHelper::storeFile(
|
|
new Section(),
|
|
new \SplFileInfo(\resource_path(
|
|
'../database/assets/schema.png'
|
|
))
|
|
), fake()->sentence(), fake()->sentence(), 1208, 374))->first(),
|
|
'bloc_image_de_la_partie2_content'
|
|
);
|
|
$quality->data = $data->all();
|
|
$quality->saveQuietly();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Reverse the migrations.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function down(): void
|
|
{
|
|
$rhd = Section::query()->where('section', PageSectionEnum::produce_rhd)->first();
|
|
if ($rhd) {
|
|
$data = collect($rhd->data);
|
|
$data->forget('bloc_lien_de_limage1_de_la_partie1');
|
|
$rhd->data = $data->all();
|
|
$rhd->saveQuietly();
|
|
} //end if
|
|
}
|
|
};
|