<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use \App\Http\Requests\SupportSaleRequest;
use Carbon\Carbon;

class SupportSalesInquiryController extends Controller
{
    public function index(Request $request)
    {
        $pid = $request->get('pid');
        $product = \App\Models\Product::where('id', '=', $pid)->where('is_front_show', '=', true)->first();
        if ($product)
        {
            $product = 'I am interested in ' . $product->title;
        }
        return view('support-sales-inquiry',[
            'productName' => $product,
        ]);
    }

    public function indexPost(SupportSaleRequest $request)
    {
        \App\Models\SupportSale::insert([
            'name_first' => $request->input('name_first'),
            'name_last' => $request->input('name_last'),
            'company_name' => $request->input('company_name'),
            'job_title' => $request->input('job_title'),
            'email' => $request->input('email'),
            'phone' => $request->input('phone'),
            'contry' => $request->input('contry'),
            'comments' => $request->input('comments'),
            'created_at' => Carbon::now(),
        ]);
        return redirect()->back()->with('success', 'We have received your sales inquiry！');
    }
}
