Init
This commit is contained in:
34
app/Models/SiteBackground.php
Normal file
34
app/Models/SiteBackground.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class SiteBackground extends Model
|
||||
{
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $fillable = [
|
||||
'date_start',
|
||||
'date_end',
|
||||
'default'
|
||||
];
|
||||
|
||||
/**
|
||||
* Returns the current IDs of active wallpaper
|
||||
*/
|
||||
public function getImages(): ? \Illuminate\Support\Collection
|
||||
{
|
||||
$now = Carbon::now();
|
||||
|
||||
$byDates = $this->whereDate('date_start', '<=', $now)->whereDate('date_end', '>=', $now)->get()->pluck('id');
|
||||
$default = $this->where('default', true)->get()->pluck('id');
|
||||
|
||||
return $byDates->isEmpty() ? $default : $byDates;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user