<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;

use App\Barang;

class InventoriController extends Controller
{
 	public function ListBarang()
    {
    	$barangs = Barang::all();
    	return view('adminlte::inventori.ListBarang.index', compact('barangs'));
    }
  	
    public function create()
    {
        return view('adminlte::inventori.ListBarang.create');
    }
   
    public function store(Request $request)
    {
        $this->validate($request, [
            'nama' => 'required',
            'jumlah' => 'required',
            'harga' => 'required',
            'deskripsi' => 'required',
            'kategori' => 'required',
            'gambar' => 'required',
        ]);

        $barangs = new Barang();
        $barangs->nama = $request['nama'];
        $barangs->jumlah = $request['jumlah'];
        $barangs->harga = $request['harga'];
        $barangs->deskripsi = $request['deskripsi'];
        $barangs->kategori = $request['kategori'];
        $barangs->gambar = $request['gambar'];
        $barangs->save();
        return redirect('ListBarang');
    }


    public function edit($id)
    {
        $barangs = Barang::where('id', $id)->first();
        return view('adminlte::inventori.ListBarang.edit')->with('barangs', $barangs);
    }


    public function update(Request $request, $id)
    {
        $this->validate($request, [
            'nama' => 'required',
            'jumlah' => 'required',
            'harga' => 'required',
            'deskripsi' => 'required',
            'kategori' => 'required',
            'gambar' => 'required',
        ]);

        $barangs = Barang::findOrFail($id);
        $barangs->nama = $request->nama;
        $barangs->jumlah = $request->jumlah;
        $barangs->harga = $request->harga;
        $barangs->deskripsi = $request->deskripsi;
        $barangs->kategori = $request->kategori;
        $barangs->gambar = $request->gambar;
        $barangs->save();
        return redirect('ListBarang');
    }



    public function destroy($id)
    {
        $barangs = Barang::find($id);
        $barangs->delete();
        return redirect('ListBarang');
    }



  	public function ListRequest()
    {
        return view('adminlte::inventori.ListRequest.index');
    }
}