ldc-legaulois/app/Http/Controllers/Fo/ConsentController.php

43 lines
1.4 KiB
PHP
Raw Permalink Normal View History

2025-11-07 11:06:31 +01:00
<?php
namespace App\Http\Controllers\Fo;
use App\Http\Controllers\Controller;
use App\Http\Requests\Fo\ConsentRequest;
2026-09-25 16:25:31 +02:00
use App\Models\OptinConsent;
use Illuminate\Contracts\View\View;
2025-11-07 11:06:31 +01:00
use LDC\LDCCRM\Exceptions\ApiErrorException;
2026-09-25 16:25:31 +02:00
use LDC\LDCCRM\Exceptions\CrmException;
2025-11-07 11:06:31 +01:00
use LDC\LDCCRM\Exceptions\ValidationException;
2026-09-25 16:25:31 +02:00
use LDC\LDCCRM\Models\SingleOptin;
2025-11-07 11:06:31 +01:00
class ConsentController extends Controller
{
/**
* Check if a customer consent to receive newsletters.
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
2026-09-25 16:25:31 +02:00
*
2025-11-07 11:06:31 +01:00
* @throws \LDC\LDCCRM\Exceptions\ValidationException ValidationException.
* @throws \LDC\LDCCRM\Exceptions\CrmException CrmException
* @throws \LDC\LDCCRM\Exceptions\ApiErrorException ApiErrorException
*/
2026-09-25 16:25:31 +02:00
public function consent(ConsentRequest $request): View
2025-11-07 11:06:31 +01:00
{
$isSubscribed = false;
if ($request->action === 'optin') {
try {
if ($optinToAdd = OptinConsent::query()->where('hashcode', $request->hashcode)->first()) {
SingleOptin::setStatus($optinToAdd->email, true);
$isSubscribed = true;
}
} catch (ValidationException | CrmException | ApiErrorException $e) {
report($e);
}
}
return view('fo.pages.newsletter-consent', compact('isSubscribed'));
}
}