<?php

namespace App\Http\Controllers;

use App\Models\Contact;
use Illuminate\Http\Request;
use Mail;
use App\Mail\MailNotify;


class ContactController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    // public function index($id='')
    // {
    //     if($id>0){
    //         $arr=Contact::where(['id'=>$id])->get();
    //         $result['name']=$arr['0']->name;
    //         $result['email']=$arr['0']->email;
    //         $result['phone']=$arr['0']->phone;
    //         $result['website']=$arr['0']->website;
    //         $result['descr']=$arr['0']->descr;

    //         $result['id']=$arr['0']->id;

    //     }else {
    //         $result['name']='';
    //         $result['email']='';
    //         $result['phone']='';
    //         $result['website']='';
    //         $result['descr']='';

    //         $result['id']='';

    //         $result['contact']=DB::table('contacts')->where(['stutas'=>1])->get();
    //     }
        
    //     return view('backend/contact_add',$result);
    // }

    public function manage_contact_process(Request $request)
    {

        $request->validate([
            'fnm'=>'required',
            'lnm'=>'required',
            'email'=>'required',
        ]);
        
        
        $model=new Contact();
        $msg="Thanks for contacting us";

        $model->fnm=$request->fnm;
        $model->lnm=$request->lnm;
        $model->email=$request->email;
        $model->phone=$request->phone;
        $model->dob=$request->dob;
        $model->budget=$request->budget;
        $model->planning=$request->planning;
        $model->descr=$request->descr;
        $model->save();
        
        if ($model->save()) {
            return back()->with(['msg'=>$msg]);
        }else {
            return back()->with(['msg'=>'Something went wrong']);
        }
    }

    public function show(Contact $contact)
    {
        $data['contacts'] = Contact::all();
        return view('backend/contact', $data);
    }

    public function delete(Request $request){
        $id = $request->id;
        $query = Contact::find($id)->delete();
        if ($query) {
            return back()->with(['msg'=>'Contact deleted succesfuly']);
        } else {
            return back()->with(['msg'=>'Something went wrong']);
        }
        
    }

}
