<?php


namespace App\Http\Controllers\frontend;
use App\Http\Controllers\Controller;
use App\Models\Devi;
use App\Models\Contact;
use App\Models\Fromcontact;
use App\Models\Categorie;
use Illuminate\Support\Facades\Mail;


use Illuminate\Http\Request;

class DeviController extends Controller
{
    public function Index(){


        $contacts = Contact::where('etat','1')->get();
        $categories = Categorie::where('etat','1')->get();


        return view('frontend/devis/devis',compact('contacts','categories'));

    }
    public function store(Request $request) {


// dd($request);
        $devis = new Devi;
        $devis->nom = $request->nom;
        $devis->email = $request->email;
        $devis->telephone = $request->telephone;

        $devis->objet = $request->objet;
        $devis->message = $request->message;

        $devis->save();



          Mail::send('frontend/devis/email-devis',
             array(
                 'nom' => $request->get('nom'),
                 'email' => $request->get('email'),
                 'telephone' => $request->get('telephone'),

                 'objet' => $request->get('objet'),

                 'user_message' => $request->get('message'),
             ),

           
			   
			     function($msg) use ($request)
               {
               
                $contactRow = Contact::where('coorType_id',"=","3")->first();
                  $msg->from($contactRow->coordonnees);
                  $msg->to($request->email);
				  $msg->subject($request->objet);
               });

               return back()->with('success', 'Merci de nous avoir contactés!');


    }
}
