<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\centry;

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

    /**
     * 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',
        ]);
        $data = new centry();
        $data->title_en = $request->title_en;
        $data->title_ps = $request->title_ps;
        $data->title_dr = $request->title_dr;
        $data->number = $request->number;
        $data->save();
        if ($data) {
            session()->flash("msg", "Success!");
            return redirect()->route('centries.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)
    {
        $data = centry::find($id);
        return view('back-end.centries.edit', compact('data'));
    }

    /**
     * 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',
        ]);
        $data = centry::find($id);
        $data->title_en = $request->title_en;
        $data->title_ps = $request->title_ps;
        $data->title_dr = $request->title_dr;
        $data->number = $request->number;
        $data->save();
        if ($data) {
            session()->flash("msg", "Success!");
            return redirect()->route('centries.index');
        }
    }

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