<?php

namespace App\Http\Controllers;

use App\DataTables\LangDataTable;
use App\Models\Lang;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;

class LangController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(LangDataTable $dataTable)
    {
        return $dataTable->render('lang.index');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $data=$this->validate($request,[
            'key'=>'required',
            'value'=>'required',
        ]);
        $data['locale']=$request->locale?$request->locale:App::currentLocale();
        return Lang::create($data);
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\Models\Lang  $lang
     * @return \Illuminate\Http\Response
     */
    public function show(Lang $lang)
    {
        return $lang;
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Models\Lang  $lang
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, Lang $lang)
    {
        $data = $this->validate($request,[
            'key'=>'required',
            'value'=>'required',
        ]);
        $data['locale']=$request->locale;

        return $lang->update($data);
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Models\Lang  $lang
     * @return \Illuminate\Http\Response
     */
    public function destroy(Lang $lang)
    {
        return $lang->delete();
    }
}
