<?php

namespace App\Http\Controllers;
use App\Municipio;
use App\Departamento;
use App\Pais;
use App\Zona;

use Illuminate\Http\Request;

class ZonasController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
        $zonas=Zona::with('paises')
                ->with('departamentos')
                ->with('municipios')
                ->get();
        return view('zonas.lista',compact('zonas'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
        $paises=Pais::all();
        $departamentos=Departamento::all();
        $municipios=Municipio::all();
        return view('zonas.nuevo',compact('paises','departamentos','municipios'));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
        $zona = new Zona();
        $zona->descripcion_zona = $request->descripcion;
        $zona->id_pais = $request->id_pais;
        $zona->id_departamento = $request->id_departamento;
        $zona->id_municipio = $request->id_municipio;
        $zona->id_user = 1;
        $zona->save();
        $arrResponse = [
            'message' => 'Zona guardada correctamente'
        ];
        return redirect()->route('zona.index')->with($arrResponse);
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
