56 lines
1.7 KiB
PHP
56 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Fo;
|
|
|
|
use App\Enums\StaticPageType;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\News;
|
|
use App\Models\Product;
|
|
use App\Models\Range;
|
|
use App\Models\StaticPage;
|
|
|
|
class RangeController extends Controller
|
|
{
|
|
/**
|
|
* Display the homepage.
|
|
*
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function index(): \Illuminate\Contracts\View\View
|
|
{
|
|
$rangeModels = Range::query()->get();
|
|
$staticPageModel = StaticPage::query()->where('type', StaticPageType::ranges)->first();
|
|
|
|
return view('fo.pages.ranges.index', compact('rangeModels', 'staticPageModel'));
|
|
}
|
|
|
|
/**
|
|
* Show a specific resource.
|
|
*
|
|
* @param string $slug
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function show(string $slug): \Illuminate\Contracts\View\View
|
|
{
|
|
$rangeModel = Range::query()->where('slug', $slug)->firstOrFail();
|
|
$rangeModels = Range::query()->where('slug', '!=', $slug)->limit(2)->inRandomOrder()->get();
|
|
$productModels = Product::query()->where('range_id', $rangeModel->id)
|
|
->where('published', true)
|
|
->orderBy('order', 'asc')
|
|
->paginate(9);
|
|
$staticPageModel = StaticPage::query()->where('type', StaticPageType::range)->first();
|
|
$newsModels = News::query()
|
|
->where('published', true)
|
|
->orderBy('created_at', 'desc')
|
|
->limit(6)
|
|
->get();
|
|
|
|
return view('fo.pages.ranges.show', compact(
|
|
'rangeModel',
|
|
'rangeModels',
|
|
'productModels',
|
|
'staticPageModel',
|
|
'newsModels'
|
|
));
|
|
}
|
|
}
|