<?php

namespace Database\Seeders;

use App\Models\SettingManagement\Link;
use Illuminate\Database\Seeder;

class LinkSeeder extends Seeder{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run(){

        $links = config('admin-links-menus');

        $this->command->info(__("Detections de :count lien(s)",['count' => count($links)]));

        foreach ($links as $link) {
            if (isset($link['sub-menus'])){
                foreach ($link['sub-menus'] as $submenu){
                    $existingLink = Link::where("title",$submenu['title'])->first();
                    if (!$existingLink){
                        Link::active()->create($submenu);
                    }
                }
            }else{
                $existingLink = Link::where("title",$link['title'])->first();
                if (!$existingLink){
                    Link::active()->create($link);
                }
            }

        }

    }
}
