<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\BoardOfDirector;

class BoardOfDirectorController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function getIndex()
    {
        return view('Admin.BoardOfDirector');
    }

    /**
     * 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, [
            
            'name'=>'required',
            'image' => 'required',
            'post' => 'required',
        ]);
        $save= new BoardOfDirector;
        $save->name=$request->name;
        $save->name_nepali=$request->name_nepali;
        $save->member_type=$request->member_type;
       
        $save->post=$request->post;
        $save->post_nepali=$request->post_nepali;
        $save->position_order=$request->position_order;
        $save->token=AdminlogController::getToken('BoardOfDirector');
        $save->save();
        AdminlogController::FileSaver( $request,'BOD',253,322);
       return redirect('admin_board_of_director')->with('info', 'Datas Saved Successfully!');
    }

    /**
     * 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)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
         $last=BoardOfDirector::where('id',$id)->first();
         $new_count=0;
         $new_count=AdminlogController::FileUpdater($request,'BOD',253,322,null,$last->token);

        $data=array(

        'member_type'=>$request->member_type,
        'name'=>$request->name,
        'post'=>$request->post,        
        'name_nepali'=>$request->name_nepali,
        'post_nepali'=>$request->post_nepali,
        'position_order'=>$request->position_order,
          
);


        BoardOfDirector::where('id',$id)->update($data);
        return redirect('admin_board_of_director')->with('info', 'Data updated Successfully!');
    }

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