2023-04-03 10:47:55 +00:00
|
|
|
<?php
|
|
|
|
|
|
2023-04-05 09:46:24 +00:00
|
|
|
namespace App\Http\Controllers\Fo;
|
2023-04-03 10:47:55 +00:00
|
|
|
|
2025-07-15 15:59:36 +02:00
|
|
|
use App\Enums\StaticPageType;
|
2023-04-05 09:46:24 +00:00
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
use App\Models\Product;
|
|
|
|
|
use App\Models\Range;
|
2025-07-15 15:59:36 +02:00
|
|
|
use App\Models\StaticPage;
|
2023-05-04 16:00:15 +02:00
|
|
|
use Illuminate\Contracts\Database\Eloquent\Builder;
|
2023-04-03 10:47:55 +00:00
|
|
|
|
|
|
|
|
class ProductController extends Controller
|
|
|
|
|
{
|
|
|
|
|
/**
|
2025-07-10 15:19:04 +02:00
|
|
|
* Products index.
|
2023-04-03 10:47:55 +00:00
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
|
*/
|
2025-07-10 15:19:04 +02:00
|
|
|
public function index(): \Illuminate\Contracts\View\View
|
2023-04-03 10:47:55 +00:00
|
|
|
{
|
2025-07-15 15:59:36 +02:00
|
|
|
$staticPageModel = StaticPage::query()->where('type', StaticPageType::products)->firstOrFail();
|
2025-07-18 10:04:12 +02:00
|
|
|
$rangeModels = Range::query()
|
|
|
|
|
->where('status', true)
|
2025-07-10 15:19:04 +02:00
|
|
|
->whereHas('products', fn(Builder $q) => $q->where('status', true))
|
|
|
|
|
->with('products', fn(Builder $q) => $q->where('status', true)->orderBy('order'))
|
2023-05-05 07:52:58 +02:00
|
|
|
->orderBy('order')
|
2025-07-10 15:19:04 +02:00
|
|
|
->get();
|
2025-07-15 15:59:36 +02:00
|
|
|
return view('fo.pages.products.index', compact('staticPageModel', 'rangeModels'));
|
2023-04-03 10:47:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-07-10 15:19:04 +02:00
|
|
|
* Product show.
|
2023-04-03 10:47:55 +00:00
|
|
|
*
|
2023-05-04 16:00:15 +02:00
|
|
|
* @param \App\Models\Product $publishedProduct
|
2023-04-03 10:47:55 +00:00
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
|
*/
|
2025-07-10 15:19:04 +02:00
|
|
|
public function show(Product $publishedProduct): \Illuminate\Contracts\View\View
|
2023-04-03 10:47:55 +00:00
|
|
|
{
|
2025-07-15 15:59:36 +02:00
|
|
|
$staticPageModel = StaticPage::query()->where('type', StaticPageType::product)->firstOrFail();
|
|
|
|
|
return view('fo.pages.products.show', [
|
|
|
|
|
'staticPageModel' => $staticPageModel,
|
|
|
|
|
'productModel' => $publishedProduct,
|
|
|
|
|
]);
|
2023-04-03 10:47:55 +00:00
|
|
|
}
|
|
|
|
|
}
|