<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\NivelIngles;

class NivelController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $niveles = NivelIngles::where('estado', '1')->get();
        return view('examen_ingles.nivel.listado', compact('niveles'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('examen_ingles.nivel.nuevo');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $data = $request->all();
        NivelIngles::create(['nombre'=>$data['nombre'], 'estado'=>'1' ]);
        return response()->json(['estado'=>'success', 'message'=>'Nivel Registrado de forma exitosa']);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        $data = $request->all();
        $nvl = NivelIngles::where('id', $id)->first();
        $nvl->nombre = $data['nombre'];
        $nvl->save();
        return response()->json(['estado'=>'success', 'message'=>'Nivel actualizado de forma exitosa.']);
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $nvl = NivelIngles::where('id', $id)->first();
        $nvl->estado = '0';
        $nvl->save();
        return response()->json(['estado'=>'success', 'message'=>'Nivel eliminado de forma exitosa.']);
    }
}
