<?php

namespace App\Http\Controllers;

use App\Models\Code;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Auth;

class CodeController extends Controller
{
    public function __construct() {
        $this->middleware('can:asistencia')->only('index','show','create');
    }

    public function index()
    {
        // $conceptos = Concepto::where('tipo','=','3')->get();
        $user = Auth::user();
        $codes= Code::where('user_id', $user->id)
        ->whereDate('registro', today())
        ->get();
        $registros=$codes->count();
        return view('code.index',compact('codes','registros'));
    }

    public function registros()
    {
        $user = Auth::user();

        $codes = Code::where('user_id', $user->id)
        ->orderBy('registro', 'desc')
        ->get()
        ->groupBy(function ($code) {
            return $code->registro->format('Y-m-d');
        });

        return view('code.show',compact('codes'));
    }
}
