<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Contact;
use App\Models\Page;

class ContactController extends Controller
{
    public function index(){
        $page = Page::where(['title' => 'Contact Us','status' => 1])->first();
        return view('contact',compact('page'));
    }

    public function post_contact(Request $request){

    $contact = new Contact();
    $subject = 'Contact Enquiry';
    // $check = '';
    // if(isset($request['firstname'])){
    //  $subject = 'Quick Enquiry';
    //  $check = '1';
    // }
    // $name = ($request['firstname'] != null) ? ($request['firstname'].' '.$request['lastname']) : $request['fullname'] ;

    $contact->fullname = $request['full_name'];
    $contact->email = $request['email'];
    $contact->phone = $request['phone'];
    $contact->message = $request['message'];
    $contact->nationality = $request['nationality'];

    $contact->save();

        // dispatch(function() use ($check,$subject, $contact) {
        \Mail::send('contact_mail', array(

            'full_name' =>$request['full_name'],

            'email' =>$request['email'],

            'phone' =>$request['phone'],

            'nationality' =>$request['nationality'],

            'contact_message' =>$request['message'],

            'subject' =>$subject 


           ), function($message) use ($subject){
            // $subject=($service!= '') ? 'Enquiry for '.$service : 'Contact/Feedback';
            $message->subject($subject);
            $message->to('admin@eteducation.com.au', 'Et-Visa')->subject($subject);
            $message->cc('extratechweb@gmail.com', 'Extratech')->subject($subject);
            $message->cc('suman@extratechs.com.au', 'Extratech')->subject($subject);

           });
        // });
        // return redirect()->back()->with(['msg' => 'Successfully submitted.']);
        return redirect()->back()->with(['msg' => 'Thank you for your interest. We will get back to you soon.','status' =>'Ok'],200);

    }
}