<?php

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

use Illuminate\Http\Request;

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

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

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
        $municipios = new Municipio();
        $municipios->descripcion_municipio = $request->descripcion;
        $municipios->id_pais = $request->id_pais;
        $municipios->id_departamento = $request->id_departamento;
        $municipios->id_user = 1;
        $municipios->save();
        $arrResponse = [
            'message' => 'Municipio guardado correctamente'
        ];
        return redirect()->route('municipio.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)
    {
        //
    }
}
