ldc-agis/app/Http/Controllers/Fo/StaticPageController.php
2023-10-27 11:41:57 +02:00

104 lines
3.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Http\Controllers\Fo;
use App\Enums\StaticPageType;
use App\Http\Controllers\Controller;
use App\Http\Requests\Fo\ContactRequest;
use App\Mail\SendContactForm;
use App\Models\Homepage;
use App\Models\News;
use App\Models\Range;
use App\Models\SeasonalSection;
use App\Models\StaticPage;
use Illuminate\Support\Facades\Mail;
class StaticPageController extends Controller
{
/**
* Legal show
*
* @param \App\Models\StaticPage $legalPage
* @return \Illuminate\Contracts\View\View
*/
public function legals(StaticPage $legalPage)
{
$legalPage = StaticPage::query()->where('type', StaticPageType::legals)
->get();
return view('fo.pages.legals', ['staticPageModel' => $legalPage[0]]);
}
/**
* Policies show
*
* @param \App\Models\StaticPage $policiesPage
* @return \Illuminate\Contracts\View\View
*/
public function policies(StaticPage $policiesPage)
{
$policiesPage = StaticPage::query()->where('type', StaticPageType::confidentiality)
->get();
return view('fo.pages.legals', ['staticPageModel' => $policiesPage[0]]);
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Contracts\View\View
*/
public function homepage(): \Illuminate\Contracts\View\View
{
/** @var \App\Models\Homepage $homepageModel */
$homepageModel = Homepage::query()->firstOrFail();
/** @var \App\Models\StaticPage $staticPageModel */
$staticPageModel = StaticPage::query()->where('type', StaticPageType::home)->firstOrFail();
/** @var \App\Models\SeasonalSection $seasonalSectionsModel */
$seasonalSectionsModel = SeasonalSection::query()->where('published', true)->first();
/** @var \App\Models\News $newsModels */
$newsModels = News::query()->where('published', true)->latest('publish_at')->limit(2)->get();
/** @var \App\Models\Range $rangeModels */
$rangeModels = Range::query()->where('published', true)->orderBy('order')->get();
return view('fo.pages.home', compact(
'homepageModel',
'staticPageModel',
'seasonalSectionsModel',
'newsModels',
'rangeModels',
));
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Contracts\View\View
*/
public function contact(): \Illuminate\Contracts\View\View
{
/** @var \App\Models\StaticPage $staticPageModel */
$contactModel = StaticPage::query()->where('type', StaticPageType::contact)->firstOrFail();
return view('fo.pages.contact', compact('contactModel'));
}
/**
* Display a listing of the resource.
*
* @param \App\Http\Requests\Fo\ContactRequest $request
* @return \Illuminate\Http\RedirectResponse
*/
public function contactForm(ContactRequest $request): \Illuminate\Http\RedirectResponse
{
Mail::to(\config('mail.from.address'))->send(new SendContactForm($request->validated()));
return redirect()->route('fo.contact.show')
->with(
'success',
'Bonjour, votre message a bien été transmis. nous vous en remercions. Cordialement, l’équipe Agis.'
);
}
}