<?php

namespace App\Http\Controllers;

use App\SupportDepartment;
use Illuminate\Http\Request;

class SupportDepartmentController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $SupportDepartments = SupportDepartment::all();
        return view('SupportDepartment.index',compact('SupportDepartments'));
    }

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

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $request-> validate([
            'title'=>'required|max:255',
            'narration'=>'max:255',
        ]);
        SupportDepartment::create($request->all());
        //dd($request);
        
        return redirect(route('SupportDepartment.index'))->with('Message','Saved Successfully');
    }

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

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\SupportDepartment  $supportDepartment
     * @return \Illuminate\Http\Response
     */
    public function edit(SupportDepartment $SupportDepartment)
    {
        return view('SupportDepartment.edit',compact('SupportDepartment')); 
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\SupportDepartment  $supportDepartment
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, SupportDepartment $SupportDepartment)
    {
        $request-> validate([
            'title'=>'required|max:255',
            'narration'=>'max:255',        
            
        ]);

        $SupportDepartment->update([
            'title'=>$request->title,
            'narration'=>$request->narration,
        ]);
        
           
        return redirect(route('SupportDepartment.index'))->with('Message','Updated Successfully');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\SupportDepartment  $supportDepartment
     * @return \Illuminate\Http\Response
     */
    public function destroy(SupportDepartment $SupportDepartment)
    {
        $SupportDepartment->delete();
        return redirect(route('SupportDepartment.index'))->with('Message','Deleted Successfully');
    }

    public static function SupportDepartmentListForCombo($SupportDepartment_id)
    {
                    $SupportDepartments=SupportDepartment::all();
                    //$Categories=['Items'=>$Items,'Selected'=>$category_id];
                    return view('SupportDepartment.combo',compact('SupportDepartments','SupportDepartment_id'));
    }
}
