<?php

namespace App\Http\Controllers\Web;

use App\Http\Controllers\Controller;
use App\Models\Category;
use App\Models\Post;
use Illuminate\Http\Request;

class PostController extends Controller
{

    public function index()
    {
        $title = 'Last News';

        $posts = Post::orderBy('id', 'desc')->get();

        return view('web.posts.index', compact('posts', 'title'));
    }

    public function show($slug)
    {


        $post = Post::findBySlugOrFail($slug);
        $posts = Post::where('id', '!=', $post->id)->orderBy('id', 'desc')->limit(2)->get();

        $title = $post->title;
        $date = $post->created_at->format('Y M');
        $title_model = $post->title;

        return view('web.posts.show', compact('post', 'posts', 'title', 'title_model' , 'date'));
    }
}
