34 lines
1.1 KiB
PHP
34 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Slide;
|
|
use App\Models\Slider;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
class HomeController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$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();
|
|
return view('front.home', compact('slider', 'slides'));
|
|
} else {
|
|
return view('front.home', compact('slider'));
|
|
}
|
|
}
|
|
}
|