Init
This commit is contained in:
35
app/Livewire/BackgroundImages.php
Normal file
35
app/Livewire/BackgroundImages.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use Livewire\Component;
|
||||
use Livewire\WithPagination;
|
||||
use Livewire\Attributes\Url;
|
||||
|
||||
use App\Models\SiteBackground;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class BackgroundImages extends Component
|
||||
{
|
||||
use WithPagination;
|
||||
|
||||
#[Url(history: true)]
|
||||
public $filter = 'all';
|
||||
|
||||
public function render()
|
||||
{
|
||||
$now = Carbon::now();
|
||||
|
||||
$images = SiteBackground::when($this->filter === 'active', fn ($query) =>
|
||||
$query->whereDate('date_start', '<=', $now)->whereDate('date_end', '>=', $now)
|
||||
)
|
||||
->when($this->filter === 'inactive', fn ($query) =>
|
||||
$query->whereDate('date_start', '>', $now)->orWhereDate('date_end', '<', $now)
|
||||
)
|
||||
->paginate(10);
|
||||
|
||||
return view('livewire.background-images', [
|
||||
'images' => $images
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user