- article_category - article - eleveur - eleveurs_sites - survey_response - fos_user - aimant_user - content_ocb - encemoment_fiche - encemoment_strates - gamme - home_slider - home_mini_slider - moment_consommation - pays - type_viande - societe - famille_vente - produit - recipe - menu - produit (update) - pictos - pictosproducts - inco_composition - qrcode - product_slider - recipe Articles - reduction - products reductions - saga - user_favorite_recipe Introduces Enum system caster and trait Html Colors auto cast for HomeSliderPictures and Ranges All migrations struct, data and model traits except HomeSliderPicture Days enum system and HomeSliderPicture migration
34 lines
1.2 KiB
PHP
34 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Enums\Days;
|
|
use App\Models\Breeders;
|
|
use App\Models\HomeSliderPictures;
|
|
use App\Models\NewsSliderPictures;
|
|
use App\Models\Products;
|
|
use Illuminate\Http\Request;
|
|
|
|
class HomeController extends Controller
|
|
{
|
|
public function index(Request $request)
|
|
{
|
|
$slides = HomeSliderPictures::where([
|
|
['days', '&', Days::make(strtolower(date('D')))],
|
|
['status', 1]
|
|
])->orderBy('order', 'ASC')->get();
|
|
|
|
$newsSlides = NewsSliderPictures::where('status', 1)->orderBy('order', 'ASC')->get();
|
|
|
|
// Images d'éleveur
|
|
$breeder = Breeders::select('picture', 'first_name', 'last_name')->where('status', 1)->inRandomOrder()->first();
|
|
|
|
// Les produits star
|
|
$starProducts = Products::select('picture', 'name', 'slug')->where([['star', 1], ['status', 1]])->inRandomOrder()->limit(3)->get();
|
|
|
|
if($starProducts->count() < 3)
|
|
$starProducts = $starProducts->concat(Products::select('picture', 'name', 'slug')->where([['star', 0], ['status', 1]])->inRandomOrder()->limit(3 - $starProducts->count())->get());
|
|
|
|
return view('home', compact('slides', 'newsSlides', 'breeder', 'starProducts'));
|
|
}
|
|
}
|