75 lines
2.3 KiB
PHP
75 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Mail;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Validation\Rule;
|
|
use App\Mail\ContactFormSubmitted;
|
|
|
|
class ContactController extends Controller
|
|
{
|
|
public function show()
|
|
{
|
|
return view('contact');
|
|
}
|
|
|
|
public function submit(Request $request)
|
|
{
|
|
$rules = [
|
|
'name' => 'required|string|max:255',
|
|
'email' => 'required|email|max:255',
|
|
'message' => 'required|string',
|
|
'image' => 'nullable|image|max:10240',
|
|
'video' => 'nullable|mimetypes:video/avi,video/mpeg,video/quicktime,video/mp4|max:512000',
|
|
];
|
|
|
|
$debugCaptcha = env('FRIENDLY_CAPTCHA_DEBUG', false)
|
|
|| (app()->environment('local')
|
|
&& (!env('FRIENDLY_CAPTCHA_SITEKEY') || !env('FRIENDLY_CAPTCHA_SECRET')));
|
|
|
|
if ($debugCaptcha) {
|
|
$rules['frc-captcha-solution'] = 'nullable';
|
|
} else {
|
|
$rules['frc-captcha-solution'] = ['required', Rule::friendlycaptcha()];
|
|
}
|
|
|
|
$request->validate($rules);
|
|
|
|
$data = $request->only(['name', 'email', 'message']);
|
|
$attachments = [];
|
|
|
|
// Handle Image
|
|
if ($request->hasFile('image')) {
|
|
// Store temporarily to attach
|
|
$imagePath = $request->file('image')->store('contact_images');
|
|
$attachments['image'] = storage_path('app/' . $imagePath);
|
|
}
|
|
|
|
// Handle Video
|
|
if ($request->hasFile('video')) {
|
|
$videoPath = $request->file('video')->store('contact_videos', 'local');
|
|
$data['video_link'] = route('contact.video', ['filename' => basename($videoPath)]);
|
|
}
|
|
|
|
// Send Email
|
|
Mail::to('info@nhgooi.nl')->send(new ContactFormSubmitted($data, $attachments));
|
|
|
|
return redirect()->route('contact')->with('success', 'Bedankt voor uw bericht. We nemen zo snel mogelijk contact met u op.');
|
|
}
|
|
|
|
public function video(string $filename)
|
|
{
|
|
$path = 'contact_videos/' . basename($filename);
|
|
|
|
if (!Storage::disk('local')->exists($path)) {
|
|
abort(404);
|
|
}
|
|
|
|
$fullPath = Storage::disk('local')->path($path);
|
|
|
|
return response()->file($fullPath);
|
|
}
|
|
}
|