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

58 lines
2.2 KiB
PHP
Raw Normal View History

2024-01-10 14:49:46 +01:00
<?php
namespace App\Http\Controllers\Fo;
use App\Http\Controllers\Controller;
2024-04-04 13:00:12 +02:00
use App\Models\ApproachSlide;
use App\Models\MainSlide;
use App\Http\Requests\Fo\SingleOptinRequest;
use LDC\LDCCRM\Enums\ApiError;
use LDC\LDCCRM\Exceptions\ApiErrorException;
use LDC\LDCCRM\Exceptions\CrmException;
use LDC\LDCCRM\Models\SingleOptin;
2024-01-10 14:49:46 +01:00
class HomeController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Contracts\View\View
*/
public function index(): \Illuminate\Contracts\View\View
{
2024-04-04 13:00:12 +02:00
$mainSlideModels = MainSlide::query()->where('published', true)->orderBy('order', 'ASC')->get();
$approachSlideModels = ApproachSlide::query()->where('published', true)->orderBy('order', 'ASC')->get();
return view('fo.pages.home', compact('mainSlideModels', 'approachSlideModels'));
2024-01-10 14:49:46 +01:00
}
/**
* Call the CRM to add a single optin
*
* @param \App\Http\Requests\Fo\SingleOptinRequest $request
* @return string|array|null|\Illuminate\Contracts\Translation\Translator
* @throws \LDC\LDCCRM\Exceptions\ValidationException ValidationException.
* @throws \Illuminate\Contracts\Container\BindingResolutionException BindingResolutionException.
*/
public function addOptIn(SingleOptinRequest $request)
{
try {
SingleOptin::setStatus($request->email, true);
return \response(trans("Votre inscription à la newsletter a été prise en compte"), 200);
} catch (ApiErrorException $e) {
// Il y a deja un customerInfo avec optin a true pour ce customer.
if ($e->getApiError()->equals(ApiError::singleOptinCustomerExists())) {
return trans('Vous êtes déjà inscrit avec cette adresse email');
}
if (app()->bound('sentry')) {
app('sentry')->captureException($e);
}
return \response(trans('Une erreur est survenue, merci de réessayer ultérieurement'), 404);
} catch (CrmException $e) {
if (app()->bound('sentry')) {
app('sentry')->captureException($e);
}
return \response(trans('Une erreur est survenue, merci de réessayer ultérieurement'), 404);
}
}
2024-01-10 14:49:46 +01:00
}