<?php

namespace Database\Seeders;

use Exception;
use File;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class ModelHasRolesTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        $this->seedOldData();
    }

    /**
     * Seed old postshop data
     */
    public function seedOldData(): void
    {
        $table = 'model_has_roles';
        DB::table($table)->delete();

        $datas = collect(json_decode(File::get('database/data/model_has_roles.json')));

        foreach ($datas as $data) {
            try {
                DB::table($table)->insert((array) $data);
            } catch (Exception $e) {
                info(['Ignore model_has_roles error', $e->getMessage()]);
            }
        }
    }
}
