<?php

namespace Database\Seeders;

use App\Models\Pages;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

class ProductDetailPageSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        Pages::where('name', 'Detail')->delete();

        $content = [
            'name' => 'Detail',
            'slug' => 'detail',
            'banner_image' => 'front/images/mainBanner.webp',
            'content' => json_encode([
               'banner_heading' => 'Product Details',
               
            ])
        ];

        $pageCollection = collect($content);

        $pageData = $pageCollection->except([
            'banner_image',
        ])->toArray();

        $service = Pages::create($pageData);

        $service->clearMediaCollection('banner_image');
        $service->addMedia(public_path($content['banner_image']))
            ->preservingOriginal()
            ->toMediaCollection('banner_image');
    }
}
