89 lines
2.8 KiB
PHP
89 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Fo;
|
|
|
|
use App\Enums\StaticPageType;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Merchandise\Product;
|
|
use App\Models\Site\Slide;
|
|
use App\Models\Site\StaticPage;
|
|
use Illuminate\Http\Request;
|
|
|
|
class StaticPageController extends Controller
|
|
{
|
|
/**
|
|
* Display static page type home
|
|
*
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function home()
|
|
{
|
|
$content = StaticPage::getPageOfType(StaticPageType::home());
|
|
// * Star products.
|
|
$products = Product::where('status', true)->where('star', true)->get();
|
|
|
|
$slides = Slide::query()->where('status', true)->get();
|
|
|
|
return view(
|
|
'theme::pages.home',
|
|
compact('content', 'products', 'slides')
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Display a static page
|
|
*
|
|
* @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory
|
|
*/
|
|
public function displayCrudStaticPageIndex()
|
|
{
|
|
return \view('theme::pages.static-page-index');
|
|
}
|
|
|
|
/**
|
|
* Display a static page
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param \App\Models\Site\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::legals():
|
|
case StaticPageType::sellconditions():
|
|
case StaticPageType::confidentiality():
|
|
case StaticPageType::faq():
|
|
return view('theme::pages.static-page', compact('static_page'));
|
|
case StaticPageType::crud():
|
|
case StaticPageType::home():
|
|
default:
|
|
if (\config('app.debug')) {
|
|
throw new \RuntimeException("Unhandled static page {$static_page->type->label}");
|
|
}
|
|
\abort(404);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Display a crud static page
|
|
*
|
|
* @param \App\Models\Site\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())) {
|
|
if (\config('app.debug')) {
|
|
throw new \RuntimeException("Unhandled static page {$static_page->type->label}");
|
|
}
|
|
\abort(404);
|
|
}
|
|
return view('theme::pages.static-page', compact('static_page'));
|
|
}
|
|
}
|