<?php

namespace App\Http\Controllers\Web;

use App\Models\Article;
use App\Models\Category;
use App\Models\Review;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\View\View;
use App\Http\Controllers\Controller;

class ArticleController extends Controller
{
    private $view = 'web.pages.articles.';


    /**
     * Show the application dashboard.
     * @return View
     */

    public function index(Request $request) :View
    {
        $title = __('web.article');
        $query = Article::withDescription();
        if($request->search)
        {
            $query->where('ad.name', 'LIKE', '%'.$request->search.'%');
        }
        if($request->category_id)
        {
            $query->where('articles.category_id', $request->category_id);
        }
        $articles = $query->paginate(6);
        $categories = Category::withDescription()->cursor();
        return view($this->view.'index', get_defined_vars());
    }


    public function show($id)
    {
        $article = Article::withDescription()->findOrFail($id);
        $articles =Article::withDescription()->where('articles.id','!=',$id)->where('articles.category_id',$article->category_id)->take(8)->get();
        $title = __('web.article_details');
        return view($this->view.'details', get_defined_vars());
    }



}
