<?php

namespace App\Http\Controllers;

use App\Rack;
use Illuminate\Http\Request;

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

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('Rack.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',
            'godown_id'=>'required',
            'narration'=>'max:255',        
            
        ]);

        Rack::create($request->all());
        return redirect(route('Rack.index'))->with('Message','Saved Successfully');
    }

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

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

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

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

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

    public static function RackListForCombo($Rack_id)
    {
                    $Racks=Rack::all();
                    return view('Rack.combo',compact('Racks','Rack_id'));
    }
}
