<?php

namespace App\Http\Controllers;

use App\Mail\RecrutementMail;
use App\Recrutement;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Storage;

class RecrutementController extends Controller
{
    public function index(Request $request , Recrutement $recrutement){
        $hasFile = $request->hasFile('file');
        $check = [
            'nom' => 'required|string',
            'prenom' => 'required|string',
            'email' => 'required|email:rfc,dns',
            'telephone' => 'required',
            'experience' => 'required|string',
            'file' => 'required', 

        ];
        $request->validate($check);
        $nom = $request->nom;
        $prenom = $request->prenom;
        $email = $request->email;
        $telephone = $request->telephone;
        $exprience = $request->exprience;
        $file = $request->file('file');
        $path =  Storage::putFile('recrutements',$file);
        // dd($path);
        $recrutement = $recrutement->create([
            'nom' => $nom,
            'prenom' => $prenom,
            'email' => $email,
            'telephone' => $telephone,
            'exprience' => $exprience,
            'cv' => $path,
        ]);
        
        Mail::to("ma.pommedepain@gmail.com")->send(new RecrutementMail($recrutement));
        return view('frontend.recrutement.index');

       
    }
}
