<?php

namespace App\Http\Controllers\Frontend;

use App\Http\Controllers\Controller;
use App\Models\Menu;
use App\Models\Product;
use Illuminate\Http\Request;

class PageController extends Controller
{
    public function showProductsByMenu($name, $slug)
    {
        $menu = Menu::where('slug', $slug)->firstOrFail();

        $products = Product::where('subcategory_id', $menu->id)
            ->latest()
            ->paginate(10);

        return view('frontend.product', compact('menu', 'products'));
    }

    public function showProductsByMainMenu($slug)
    {
        $menu = Menu::where('slug', $slug)->firstOrFail();

        $products = Product::where('category_id', $menu->id)
            ->orWhere('subcategory_id', $menu->id)
            ->latest()
            ->paginate(10);

        return view('frontend.product', compact('menu', 'products'));
    }
}
