<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;
use \App\Contato;

use App\Exports\ContatoExport;
use App\Exports\ContatoExportView;
use Maatwebsite\Excel\Facades\Excel;

class ContatoController extends Controller
{

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        if (Gate::denies('contatos-view')){
            abort(403, "Não autorizado");
        }

        $objs = Contato::orderBy('id', 'DESC')->paginate(30);
        $caminhos = [
            ['url' => '/admin', 'titulo' => 'Admin'],
            ['url' => '', 'titulo' => 'Contatos'],
        ];
        return view('admin.contatos.index', compact('objs', 'caminhos'));
    }

    public function export(Request $request){
        if (Gate::denies('contatos-export')){
            abort(403, "Não autorizado");
        }

        $dt_inicial = $request['dt_inicial'];
        $dt_final = $request['dt_final'];


        return Excel::download(new ContatoExport($dt_inicial, $dt_final), 'contatos.xlsx');
    }

  
}
