<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\systemAdministration\language;
use Auth;

class LanaguageController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $language = language::orderBy('id', 'desc')->paginate(20);
        return view('back-end.language.create', compact('language'));
    }

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

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $this->validate($request, [
            'title_en' => 'required',
        ]);
        $language = new language();
        $language->title_en = $request->title_en;
        $language->title_ps = $request->title_ps;
        $language->title_dr = $request->title_dr;
        $language->save();
        if ($language) {
            session()->flash("msg", "Success!");
            return redirect()->route('language.index');
        }
    }

    /**
     * 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)
    {
        $language = language::find($id);
        return view('back-end.language.edit', compact('language'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        $this->validate($request, [
            'title_en' => 'required',
        ]);
        $language = language::find($id);
        $language->title_en = $request->title_en;
        $language->title_ps = $request->title_ps;
        $language->title_dr = $request->title_dr;
        $language->save();
        if ($language) {
            session()->flash("msg", "Success!");
            return redirect()->route('language.index');
        }
    }

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