<?php

namespace App\Http\Controllers;

use App\Models\DSAMaster;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class DSAMasterController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $dsaMaster = DB::table("daschannel")->get();
        return view("layouts.dsaMaster",["dsaMaster"=>$dsaMaster]);
    }

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

        return view("layouts.AddDSA");
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */

    public function store(Request $request){

        $dsadata = new DSAMaster;
        $dsadata->name = $request->name;
        
        $dsadata->location = $request->location;
        
        
        $dsadata->status = 'active';
        $dsadata->save();
        return redirect("dsaMaster")->with("status","Saved successfully");
    }

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

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\Models\DSAMaster  $dSAMaster
     * @return \Illuminate\Http\Response
     */

    public function edit(DSAMaster $dSAMaster,$id){

        $data        = DB::table("daschannel")->where("id",$id)->get();
        $EDITdatadsa = json_decode( json_encode($data),true);
        //echo "<pre>";print_r($EDITdatadsa); die();
        return view("layouts.EditDSAMaster",["EDITdatadsa"=>$EDITdatadsa]);
    
    }

    /**
    
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Models\DSAMaster  $dSAMaster
     * @return \Illuminate\Http\Response
     *
     */

    public function update(Request $request){
        
        // echo 'ss'; die();
        $id        = $request->input("id");
        $upData    = array(
            "name" => $request->input("name"),
            "location" => $request->input("location"),
            "status" => $request->input("status")
        );

        DB::table("daschannel")->where("id",$id)->update($upData);
        return redirect("dsaMaster")->with("status","Update Successfully");
        
    }

    /**
     * 
     * Remove the specified resource from storage.
     *
     * @param  \App\Models\DSAMaster  $dSAMaster
     * @return \Illuminate\Http\Response
     */

    public function destroy(DSAMaster $dSAMaster,$id){        
        DB::table("daschannel")->where("id",$id)->delete();
        return redirect("dsaMaster")->with("status","Deleted Successfully");
    }
}
