<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\sayur;
use App\cabe;
use App\ubi;
use App\tomat;
use App\andaliman;
use App\keranjang;
use App\jagung;
use App\kentang;
use App\kacang;
use Illuminate\Support\Facades\Input;
use App\Http\Requests;
use App\Http\Requests\sayur\StoreRequest;
use App\Http\Requests\sayur\UpdateRequest;
use Image;

class belisayurcontroller extends Controller
{
    public function index()
    {
        $keranjangs = keranjang::all();
        return view('Costumer.HalamanMonitoring.keranjang_index', compact('keranjangs'));
    }

    public function costsayur()
    {
        $sayurs = sayur::all();
        return view('Costumer.HalamanMonitoring.monitoringsayur', compact('sayurs'));
    }
    public function costcabe()
    {
        $cabes = cabe::all();
        return view('Costumer.MonitoringCabe.monitoringcabe', compact('cabes'));
    }
    public function costubi()
    {
        $ubis = ubi::all();
        return view('Costumer.MonitoringUbi.monitoringubi', compact('ubis'));
    }
    public function costtomat()
    {
        $tomats = tomat::all();
        return view('Costumer.HalamanTomat.index', compact('tomats'));
    }
    public function costandaliman()
    {
        $andalimans = andaliman::all();
        return view('Costumer.MonitoringAndaliman.index', compact('andalimans'));
    }
    public function costjagung()
    {
        $jagungs = jagung::all();
        return view('Costumer.HalamanJagung.index', compact('jagungs'));
    }
    public function costkentang()
    {
        $kentangs = kentang::all();
        return view('Costumer.MonitoringKentang.monitoringkentang', compact('kentangs'));
    }
    public function costkacang()
    {
        $kacangs = kacang::all();
        return view('Costumer.MonitoringKacang.index', compact('kacangs'));
    }



    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */

    public function create()
    {
        return view('Admin.HalamanMonitoring.create');
    }

    public function siram()
    {
        return view('Admin.HalamanMonitoring.siram');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */

    public function store(Request $request)
    {
        $keranjangs = new keranjang();

        $keranjangs->username = $request->username;
        $keranjangs->nama = $request->nama;
        $keranjangs->family = $request->family;
        $keranjangs->tanggal_tanam = $request->tanggal_tanam;
        $keranjangs->usia = $request->usia;
        $keranjangs->hama = $request->hama;
        $keranjangs->syarat_tumbuh = $request->syarat_tumbuh;
        $keranjangs->pemeliharaan = $request->pemeliharaan;
        $keranjangs->Harga = $request->Harga;


//        $image = Input::file('image');
//        var_dump($image);
//        Input::file('image')->getClientOriginalExtension();
//        $filename = date('Y-m-d-H:i:s')."-".$image->getClientOriginalName();
//        Image::make($image->getRealPath())->resize(468, 249)->save('public/image/'. $filename);
//        $sayurs->foto = 'image/ '. $filename;
//
//        $filename = $image[0]->getClientOriginalName();
//        print_($filename);


//        if ($request->hasFile('files_field')) {
//            $file= $request->Input('files_field');
//
//            $destination_path='image/';
//
//            $Orname = $file->getClientOriginalName();
//
//            $filename= str_random(6).'_'.$Orname;
//
//            $file->move($destination_path,$filename);
//
//            $sayurs->foto = $destination_path.$filename;
//        }






        $keranjangs->save();
        return redirect()->route('beli.index')->with('alert-success', 'Data Berhasil Disimpan.');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        $sayurs = sayur::findOrFail($id);
        return view('costumer.HalamanMonitoring.lihat', compact('sayurs'));
    }
    public function show1($id)
    {
        $sayurs = sayur::findOrFail($id);
        return view('Admin.HalamanMonitoring.lihat', compact('sayurs'));
    }



    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $sayurs = sayur::findOrFail($id);
        return view('Admin.HalamanMonitoring.edit', compact('sayurs'));
    }



    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(UpdateRequest $request, $id)
    {

        $sayurs = sayur::findOrFail($id);
        $sayurs->nama = $request->nama;
        $sayurs->family = $request->family;
        $sayurs->tanggal_tanam = $request->tanggal_tanam;
        $sayurs->usia = $request->usia;
        $sayurs->hama = $request->hama;
        $sayurs->syarat_tumbuh = $request->syarat_tumbuh;
        $sayurs->pemeliharaan = $request->pemeliharaan;
        $sayurs->Harga = $request->Harga;

        $sayurs->save();
        return redirect()->route('HalamanMonitoring.index')->with('alert-success', 'Data Berhasil Diubah.');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $sayurs = sayur::findOrFail($id);
        $sayurs->delete();
        return redirect()->route('HalamanMonitoring.index')->with('alert-success', 'Data Berhasil Dihapus.');
    }
}
