45 lines
1.4 KiB
PHP
45 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Fo;
|
|
|
|
use App\Enums\StaticPageType;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Product;
|
|
use App\Models\Range;
|
|
use App\Models\StaticPage;
|
|
use Illuminate\Contracts\Database\Eloquent\Builder;
|
|
|
|
class ProductController extends Controller
|
|
{
|
|
/**
|
|
* Products index.
|
|
*
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function index(): \Illuminate\Contracts\View\View
|
|
{
|
|
$staticPageModel = StaticPage::query()->where('type', StaticPageType::products)->firstOrFail();
|
|
$rangeModels = Range::query()
|
|
->where('status', true)
|
|
->whereHas('products', fn(Builder $q) => $q->where('status', true))
|
|
->with('products', fn(Builder $q) => $q->where('status', true)->orderBy('order'))
|
|
->orderBy('order')
|
|
->get();
|
|
return view('fo.pages.products.index', compact('staticPageModel', 'rangeModels'));
|
|
}
|
|
|
|
/**
|
|
* Product show.
|
|
*
|
|
* @param \App\Models\Product $publishedProduct
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function show(Product $publishedProduct): \Illuminate\Contracts\View\View
|
|
{
|
|
$staticPageModel = StaticPage::query()->where('type', StaticPageType::product)->firstOrFail();
|
|
return view('fo.pages.products.show', [
|
|
'staticPageModel' => $staticPageModel,
|
|
'productModel' => $publishedProduct,
|
|
]);
|
|
}
|
|
}
|