initial: bootstrap from BukidBountyApp base
This commit is contained in:
59
app/Models/Announcement.php
Normal file
59
app/Models/Announcement.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Model;
|
||||
|
||||
class Announcement extends Model
|
||||
{
|
||||
protected ?string $table = 'announcements';
|
||||
|
||||
public bool $incrementing = true;
|
||||
|
||||
protected array $fillable = [
|
||||
'title',
|
||||
'content',
|
||||
'photo',
|
||||
'hashkey',
|
||||
'type',
|
||||
'is_active',
|
||||
'starts_at',
|
||||
'ends_at',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
];
|
||||
|
||||
protected array $casts = [
|
||||
'is_active' => 'boolean',
|
||||
'starts_at' => 'datetime',
|
||||
'ends_at' => 'datetime',
|
||||
'created_by' => 'integer',
|
||||
'updated_by' => 'integer',
|
||||
];
|
||||
|
||||
public function creator()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'created_by');
|
||||
}
|
||||
|
||||
public function updater()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'updated_by');
|
||||
}
|
||||
|
||||
public function scopeActive($query)
|
||||
{
|
||||
$now = now();
|
||||
return $query->where('is_active', true)
|
||||
->where(function ($q) use ($now) {
|
||||
$q->whereNull('starts_at')
|
||||
->orWhere('starts_at', '<=', $now);
|
||||
})
|
||||
->where(function ($q) use ($now) {
|
||||
$q->whereNull('ends_at')
|
||||
->orWhere('ends_at', '>=', $now);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user