<?php

namespace App\Http\Controllers\Admin\Masters;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Masters\TyreBrands;
use Illuminate\Support\Facades\Redirect;

class TyreBrandsController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        //
        $type = TyreBrands::orderBy('id', 'DESC')->get();

        return view('masters.tyre_brand', compact('type'));
    }

    /**
     * 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)
    {

        $type = new TyreBrands;
        $type->name = $request->input("name");
        $type->save();
        
        session()->flash('success', 'Brand added successfully.');
        return Redirect::back();
    }
    
    public function update(Request $request)
    {
        $id = $request->input("brand_id");
        $type = TyreBrands::find($id);
        $type->name = $request->input("name");
        $type->save();
        
        session()->flash('success', 'Brand updated successfully.');

        return Redirect::back();
    }
   

    public function destroy($id)
    {
        //
        $type = TyreBrands::find($id);
        $type->delete();
        session()->flash('success', 'Brand deleted successfully.');
        
        return Redirect::back();
    }

}
