<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use DB;
use App\ContactUs;
use App\Metatag;
use Mail;
use Notification;
use App\Notifications\NewInquiry;
use App\Recipients\AdminRecipient;
use App\Recipients\DynamicRecipient;

class ContactController extends Controller
{
    //


    public function index(){

        $data = [];

        $data['metatags']  = Metatag::where('mt_page', '=', 'c')->select('mt_title as title','mt_desc as desc','mt_keyw as keyw', 'mt_h1 as h1')->first();

        return view('frontend.contact',$data);

    }


    public function store(Request $request){

        //dd($request->all());

        $this->validate($request, [
            'name' => 'required',
            'email' => 'required|email',
            'message' => 'required'
        ]);

        $contactUs = ContactUs::create($request->all());

        //$recipient = new DynamicRecipient('info@msgroup.rs', 'MS Group');
        //Notification::send($recipient, new NewInquiry($contactUs));

        $recipient = new AdminRecipient();
        $recipient->notify(new NewInquiry($contactUs));

        $url = ( config('app.locale') == 'sr') ? '/sr/contact' : '/contact';

        return redirect($url)->with('success', __('frontside.contact.thank_you'));

    }



}
