<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;


use App\User;
use App\Bmw;
use App\Ducati;
use App\Bike;

class UsersController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    // public function index()
    // {
    //     $bikes = Bike::all();
    //
    //     dd($user_id);
    // }

    public function indexa(Request $request)
    {
        $bikes = Bike::all();
        $user_id = $request->User()["type"];
        return view('index',compact('bikes','user_id'));
    }




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

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
                $user = new Bike(
                [
                    'NameProduct' => $request->get('NameProduct'),
                    'Price' => $request->get('Price'),
                    'Detail' => $request->get('Detail'),
                    'Img' => $request->get('Img')
                ]
                );
                $bikes = Bike::all()->toArray();
                $user->save();
                return view('admin.dashboard', compact('bikes'));
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        $products = Bike::find($id);
        return view('product', compact('products'));
    }

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


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

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $user = bikes::find($id);
        $user->delete();
        return back();
    }

}
