<?php

namespace App\Http\Controllers;

use App\Models\Language;
use Illuminate\Http\Request;
use Illuminate\Http\Response;

class LanguageController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function index()
    {
        return Language::all();
    }

    public function store(Request $request)
    {

        Language::create($this->validateRequest($request));
        return back(303)->with(['success' => 'success']);

    }

    /**
     * Show the form for creating a new resource.
     *
     * @return Response
     */
    public function create()
    {

    }

    public function validateRequest(Request $request)
    {
        return $request->validate(
            [
                'name' => 'required',
            ]
        );
    }

    /**
     * Display the specified resource.
     *
     * @param Language $language
     * @return Response
     */
    public function show(Language $language)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param Language $language
     * @return Response
     */
    public function edit(Language $language)
    {
        //
    }

    public function update(Request $request, Language $language)
    {

        $language->update($this->validateRequest($request));
        return back(303)->with(['success' => 'success']);
    }

    public function destroy(Language $language)
    {
        $language->delete();
        return back(303)->with(['success' => 'success']);
    }
}
