<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Spatie\Permission\Models\Role;
use Spatie\Permission\Models\Permission;
use App\User; 
use App\Post;
use App\Category;
use Auth;
use File;
use Validator;


class Categorys extends Controller
{

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Contracts\Support\Renderable
     */
    public function index()
    {
        $Genres =  Category::all();
        return view('Pages.Cat.index',compact('Genres'));
    }
    /**
     * Display the specified resource.
     *
     * @param  int  $slug
     * @return \Illuminate\Http\Response
     */
    
    public function show($slug)
    { 
        $Categores  = Category::all();
        //To Get All Category 
        $Category = Category::where('slug', '=', $slug)->firstOrFail();
        //To Get All Posts
        $Posts = Post::where('category_id','=', $Category->id)->oldest()->simplepaginate(10);
        //To Get All Posts
        $SlidePosts  = Post::oldest()->simplepaginate(10);
        return view('Pages.Cat.show',compact('Posts','Category','SlidePosts','Categores'));
       
    }
}