<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Video;

class VideoController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function getIndex()
    {   $save=Video::all();
        return view('Admin.Video')->with('save',$save);
    }

    /**
     * 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'=>'required',
            'link' => 'required',
        ]);
        $save= new Video;
        $save->title=$request->title;
        $save->title_nepali=$request->title_nepali;
        $save->link= $request->link;
        $save->save();
       return redirect('admin_video')->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)
    {
        $editVideo=Video::where('id',$id)->first();
        return redirect('admin_video')->with('edit',$editVideo);
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
             $data=array(
            'title'=>$request->title,
            'title_nepali'=>$request->title_nepali,
            'link'=>$request->link,
            
                
        );
         


          

        Video::where('id',$id)->update($data);
        return redirect('admin_video')->With('info',"Successfully updated");
    }
           

   

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
   
    Video::where ('id',$id)->delete();
    return redirect('admin_video')->With('info'," Successfully deleted");
    }
}
