<?php

namespace App\Http\Controllers;

use App\Models\Chauffeur;
use Illuminate\Http\Request;

class IndexController extends Controller
{
    //
     public function index()
    {
        return view('index');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $data = request()->validate([
            'nom' => ['required', 'string'],
            'prenom' => ['required', 'string'],
            'commune' => ['required', 'string'],
            'groupesang' => ['required', 'string'],
            'telephone' => ['required', 'string'],
            'nationalite' => ['required', 'string'],
            'cni' => ['required', 'string'],
            'fonction' => ['required', 'string'],
            'dateadh' => ['required', 'date'],
            'permis' => ['required', 'string'],
            'photo' => ['required', 'string']
        ]);
        //dd($request->all()); 
        try {
            $data['nom'] = $request->nom;
            $data['prenom'] = $request->prenom;
            $data['groupesang'] = $request->groupesang;
            $data['telephone'] = $request->telephone;
            $data['nationalite'] = $request->nationalite;
            $data['cni'] = $request->cni;
            $data['permis'] = $request->permis;
            $data['fonction'] = $request->fonction;
            $data['date'] = date("Y-m-d H:i:s");
            $data['commune'] = $request->commune;
            $data['photo'] = $request->photo;
            $data['etat'] = 'NEW';
        } catch (\Throwable $th) {
            dd($th->getMessage());
        }
        Chauffeur::create($data);
        return redirect('/')->with('success', 'Merci pour votre enregistrement');
        dd($response->json());
    }
}
