<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Post;
use App\BlogCategories;
use App\Video;
use Illuminate\Support\Facades\Validator;
use App\Subscriber;
use DB;
use App\Widgets;
class BlogController extends FrontController
{
    public function __construct() {
         $this->breadcrumbs = $this->getBreadcrumbs();
        $this->breadcrumbs[1]['link'] = "news";
        $this->breadcrumbs[1]['name'] = "News"; 
    }
    
    public function index() {
        
        $data["blogCategories"]=BlogCategories::get();
        $data["blogs"]=Post::paginate(9);
        $data["headerClass"]='';
        $data["active_cat"] = "all";
        return view('front/blogs',$data);
       
    }
    public function blogCategories($id) {
        
        if (empty($id)) {
            $errors = $validator->errors();
            $response['errors'] = $errors;
            $response['error'] = true;
            $header = 402;
        } else {
            $key = BlogCategories::where('key',$id)->first();
            $response["blogCategories"]=BlogCategories::get();
            $response["headerClass"]='';
            $response["blogs"]=Post::where('category_id',$key->id)->paginate(9);
            $response["banner_title"] = $key->title;
            $response["active_cat"] = $key->key;
            $header = 200;
            $response['error'] = false;
        }
        
        return view('front/blogs',$response);
       
    }
    
    public function blog($key){
        $model = Post::where('key', $key)->where('status', 1)->first();
        
        $inc=[];
        if(isset($model->id)){
            $n=$model->id;
            $inc = Post::where('id', ($n +1))->where('status', 1)->first();
            $data["incData"]=$inc;
            $data["model"]=$model;
            $data["category"] = BlogCategories::where('status', 1)->get();
        
            $data["headerClass"]='';
//        $this->breadcrumbs[2]['link'] = "#_";
//        $this->breadcrumbs[2]['name'] = $data['model']->title ;
//      
//        $data['breadcrumbs'] = $this->breadcrumbs;
            return view('front/blog',$data);
        }else{
            abort("404");
        }
    }
 
}

