<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\StatusCategory;


class StatusCategoryController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $status = StatusCategory::orderBy('id' , 'DESC')->get();
        
        return view('Admin.StatusCategory.index' , compact('status'));
    }

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

    /**
     * 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',
            'status' => 'required'
        ]);
            
        StatusCategory::create($request->all()); 
        return redirect()->route('StatusCategory.index')->with('success_message' , 'Record Successfully Created');
    }

    /**
     * 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)
    {
        $status = StatusCategory::find($id);
        
        return view('Admin.StatusCategory.update' , compact('status'));
    }

    /**
     * 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 , [
            'name' => 'required',
            'status' => 'required'
        ]);
            
        StatusCategory::find($id)->update($request->all()); 
        return redirect()->route('StatusCategory.index')->with('success_message' , 'Record Successfully Updated!');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        StatusCategory::find($id)->delete();
        return redirect()->route('StatusCategory.index')->with('success_message' , 'Record Successfully Deleted!');
  
    }
}
