79 lines
2.6 KiB
PHP
79 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Fo;
|
|
|
|
use App\Enums\StaticPageType;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Product;
|
|
use App\Models\Slider;
|
|
use App\Models\StaticPage;
|
|
use Illuminate\Http\Request;
|
|
|
|
class StaticPageController extends Controller
|
|
{
|
|
/**
|
|
* Display static page type home
|
|
*
|
|
* @param Request $request
|
|
* @return \Illuminate\Contracts\View\View
|
|
*
|
|
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
|
*/
|
|
public function home(Request $request)
|
|
{
|
|
// @phpcs:enable
|
|
$content = StaticPage::getPageOfType(StaticPageType::home());
|
|
// Star products.
|
|
$products = Product::where('status', true)->where('star', true)->get();
|
|
|
|
$slider = Slider::where('slug', 'home')->first();
|
|
$slides = $slider->showable_slides;
|
|
|
|
return view(
|
|
'theme::pages.home',
|
|
compact('content', 'products', 'slides')
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Display a static page
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param \App\Models\StaticPage $static_page_front
|
|
* @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory
|
|
* @throws \RuntimeException If the static page type is not handled.
|
|
*/
|
|
public function displayStaticPage(Request $request, StaticPage $static_page_front)
|
|
{
|
|
$static_page = $static_page_front;
|
|
switch ($static_page->type) {
|
|
case StaticPageType::contact():
|
|
return app(ContactController::class)->contact($request);
|
|
case StaticPageType::home():
|
|
return $this->callAction('home', [$request]);
|
|
case StaticPageType::legals():
|
|
case StaticPageType::sellconditions():
|
|
case StaticPageType::confidentiality():
|
|
case StaticPageType::faq():
|
|
return view('theme::pages.static-page', compact('static_page'));
|
|
case StaticPageType::crud():
|
|
default:
|
|
throw new \RuntimeException("Unhandled static page {$static_page->type->label}");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Display a crud static page
|
|
*
|
|
* @param \App\Models\StaticPage $static_page
|
|
* @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory
|
|
* @throws \RuntimeException If the static page type is not handled.
|
|
*/
|
|
public function displayCrudStaticPage(StaticPage $static_page)
|
|
{
|
|
if (!$static_page->type->equals(StaticPageType::crud())) {
|
|
throw new \RuntimeException("Unhandled static page {$static_page->type->label}");
|
|
}
|
|
return view('theme::pages.static-page', compact('static_page'));
|
|
}
|
|
}
|