54 lines
1.7 KiB
PHP
54 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Enums\Page;
|
|
use App\Models\Encart;
|
|
use App\Models\Post;
|
|
use App\Models\Product;
|
|
use App\Models\SeoDatum;
|
|
use App\Models\Slide;
|
|
use App\Models\Slider;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
class HomeController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
|
|
$page = Page::home();
|
|
$seoDatum = SeoDatum::where('page', $page)->first();
|
|
|
|
$slider = Slider::where('published', 1)->first();
|
|
if ($slider) {
|
|
$slides = Slide::whereHas('slider', function ($q) use ($slider) {
|
|
$q->whereId($slider->id);
|
|
})->where(function ($q) {
|
|
$q->where(
|
|
function ($q) {
|
|
$q->where('date_start', '<=', Carbon::now()->format('Y-m-d H:i:s'))
|
|
->where('date_end', '>', Carbon::now()->format('Y-m-d H:i:s'));
|
|
}
|
|
)->orWhere(function ($q) {
|
|
$q->whereNull('date_start')
|
|
->whereNull('date_end');
|
|
});
|
|
})->orderBy('order', 'ASC')
|
|
->get();
|
|
} else {
|
|
$slides = null;
|
|
}
|
|
|
|
$encart_home = Encart::where('page', Page::homeHeader()->value)->first();
|
|
|
|
$post_home = Post::where([
|
|
['date_start', '<=', Carbon::now()->format('Y-m-d H:i:s')],
|
|
['date_end', '>', Carbon::now()->format('Y-m-d H:i:s')],
|
|
['on_top', true]
|
|
])->first();
|
|
// Limitation à 3 produits affichés sur la homepage
|
|
$products_home = Product::where('is_on_top', true)->take(3)->get();
|
|
|
|
return view('front.home', compact('slider', 'slides', 'seoDatum', 'encart_home', 'post_home', 'products_home'));
|
|
}
|
|
}
|