<?php

namespace App\Http\Controllers;

use App\Good;
use App\Log;
use App\Trace;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Vinkla\Hashids\Facades\Hashids;

class HomeController extends Controller
{
<<<<<<< HEAD
    public function key(Request $request, $key)
    {
        $id = Hashids::decode($key)[0];
        $trace = Trace::findOrFail($id);
        if (is_null($trace->look_time)) {
=======
    public function key(Request $request,$key){
        $id = Hashids::decode($key)[0];
        $trace = Trace::findOrFail($id);
        if(is_null($trace->look_time)){
>>>>>>> 7eb6db16d74fecdf152724ce124c7f83233ad8ee
            $trace->look_time = Carbon::now();
        }

        $trace->look_count += 1;
        $trace->save();

        Log::create([
            'gid' => $trace->gid,
            'tid' => $trace->id,
            'ip' => $request->getClientIp()
        ]);

        $good = Good::find($trace->gid);

<<<<<<< HEAD
        $dealer = $trace->dealer;
        dd($dealer);

        $templat = collect(Good::$templetOption)->where('id', $good->templet)->first()['value'] ?? 'key';
        return view("home.{$templat}", compact('good', 'trace'));
=======
        $templat = Good::$templetOption[$good->templet]['value'] ?? 'key';
        return view("home.{$templat}",compact('good','trace'));
>>>>>>> 7eb6db16d74fecdf152724ce124c7f83233ad8ee
    }
}
