first commit
This commit is contained in:
70
app/Http/Controllers/Frontend/ContactUsController.php
Normal file
70
app/Http/Controllers/Frontend/ContactUsController.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Frontend;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Frontend\ContactUs;
|
||||
use App\Models\Admin\contact_us_details;
|
||||
use Mail;
|
||||
use App\Mail\Frontend\ContactUsMail;
|
||||
use App\Mail\Frontend\AdminNotificationEmail;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
|
||||
|
||||
class ContactUsController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$contact_us_detail = contact_us_details::all()->toArray();
|
||||
return view('Frontend.Pages.Contact_us.contact_us')->with(['contact_us'=>$contact_us_detail]);
|
||||
}
|
||||
|
||||
public function index_thank_you()
|
||||
{
|
||||
return view('Frontend.Pages.Contact_us.thank_you_contact');
|
||||
}
|
||||
|
||||
public function insert_contact(Request $request)
|
||||
{
|
||||
$validator = $request->validate([
|
||||
'contact_name' => 'required',
|
||||
'contact_email' => 'required',
|
||||
'contact_title' => 'required',
|
||||
'captcha' => 'required|captcha'
|
||||
],[
|
||||
'captcha.required' => 'The captcha field is required.',
|
||||
'captcha.captcha' => 'The captcha verification failed.'
|
||||
]);
|
||||
|
||||
$contact = new ContactUs;
|
||||
$contact->name = $request->input('contact_name');
|
||||
$contact->email = $request->input('contact_email');
|
||||
$contact->title = $request->input('contact_title');
|
||||
$contact->message = $request->input('message');
|
||||
$contact->save();
|
||||
//
|
||||
// Mail::to($contact->email)->send(new ContactUsMail($contact));
|
||||
// // Send email to admin
|
||||
// Mail::to('dipti@wdimails.com')->send(new AdminNotificationEmail($contact));
|
||||
//
|
||||
try {
|
||||
// Send email to contact
|
||||
Mail::to($contact->email)->send(new ContactUsMail($contact));
|
||||
|
||||
// Send email to admin
|
||||
Mail::to('sneha@wdimails.com')->send(new AdminNotificationEmail($contact));
|
||||
} catch (\Exception $e) {
|
||||
// Log and handle the exception
|
||||
\Log::error('Email sending failed: ' . $e->getMessage());
|
||||
}
|
||||
// Return success response
|
||||
return response()->json(['success' => true, 'status' => 200]);
|
||||
}
|
||||
|
||||
public function reloadCaptcha()
|
||||
{
|
||||
return response()->json(['captcha'=> captcha_img('flat')]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user