34 lines
954 B
PHP
34 lines
954 B
PHP
<?php
|
|
|
|
namespace Database\Seeders\Mandatory;
|
|
|
|
use App\Models\CommitmentPage;
|
|
use App\Models\Picto;
|
|
use Illuminate\Database\Seeder;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\File;
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
class CommitmentPageSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function run()
|
|
{
|
|
Schema::disableForeignKeyConstraints();
|
|
DB::table((new CommitmentPage())->getTable())->truncate();
|
|
Schema::enableForeignKeyConstraints();
|
|
|
|
File::deleteDirectory(\storage_path('app/public/modelfiles/' . (new Picto())->getTable()));
|
|
|
|
CommitmentPage::factory(1)->createQuietly();
|
|
|
|
$pictos = Picto::query()->get();
|
|
CommitmentPage::query()->each(function (CommitmentPage $commitmentPage) use ($pictos) {
|
|
$commitmentPage->pictos()->saveManyQuietly($pictos->random(\rand(0, 2)));
|
|
});
|
|
}
|
|
}
|