<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Models\DistProduct;
use App\Models\DistPages;
use App\Models\DistVideo;

class SitemapController extends Controller
{

    //sitemap 特殊，使用内置模板来生成
    public function index()
    {
        // 获取产品、文章和视频数据
        $dist_products = DistProduct::where('enabled', 1)->where('dist_id', getDistId())->get(); // 获取所有字段
        $dist_pages = DistPages::where('status', 1)->where('dist_id', getDistId())->get(); // 获取所有字段
        $dist_videos = DistVideo::where('enabled', 1)->where('dist_id', getDistId())->get(); // 获取所有字段


        // 创建一个视图来生成 XML
        return response()->view('sitemap.index', [
            'dist_products' => $dist_products,
            'dist_pages' => $dist_pages,
            'dist_videos' => $dist_videos,
        ])->header('Content-Type', 'application/xml');
    }
}
