<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Instruksi;
use App\Scan;
use App\User;

class InstruksiController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $instruksi = Instruksi::where('aktif', 1)
                                ->first();
                                
        return $instruksi;
    }

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

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

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request)
    {
        $barcode = Instruksi::find($request->barcode_id);
        $user = User::find($request->user_id);
        
        $user->poin += $barcode->poin;
        $user->update();
        $barcode->discan = 1;
        $barcode->update();
        
        $scan = new Scan();
        $scan->user_id = $request->user_id;
        $scan->barcode_id = $request->barcode_id;
        $scan->save();
        
        return $barcode;
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
