<?php

namespace App\Http\Controllers\Web;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\{Contact, Article, ProductCategory, About};

class ArticleController extends Controller
{
    public function index(Request $request){
        $q_name = $request->q_name;
        $q_category_id = $request->q_category_id;
        $category_name = "";
        $about = About::first();

        $product_category = ProductCategory::limit(5)->get();
        $contact = Contact::first();

        $article = Article::orderBy('id', 'desc')->get();

        return view('apps.web.article')->with('category_name' ,$category_name)
                                       ->with('q_name', $q_name)
                                       ->with('article', $article)
                                       ->with('about', $about)
                                       ->with('q_category_id', $q_category_id)
                                       ->with('product_category', $product_category)
                                       ->with('contact', $contact);
        
    }

    public function detail(Request $request, Article $article){
        $q_name = $request->q_name;
        $q_category_id = $request->q_category_id;
        $category_name = "";
        $about = About::first();

        $product_category = ProductCategory::limit(5)->get();
        $contact = Contact::first();

        return view('apps.web.detail_article')->with('category_name' ,$category_name)
                                       ->with('q_name', $q_name)
                                       ->with('article', $article)
                                       ->with('about', $about)
                                       ->with('q_category_id', $q_category_id)
                                       ->with('product_category', $product_category)
                                       ->with('contact', $contact);
    }
}
