Initialer Laravel Commit für BetiX
This commit is contained in:
51
app/Models/Bonus.php
Normal file
51
app/Models/Bonus.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Bonus extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'title',
|
||||
'type',
|
||||
'amount_value',
|
||||
'amount_unit',
|
||||
'min_deposit',
|
||||
'max_amount',
|
||||
'currency',
|
||||
'code',
|
||||
'status',
|
||||
'starts_at',
|
||||
'expires_at',
|
||||
'rules',
|
||||
'description',
|
||||
'created_by',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'amount_value' => 'decimal:8',
|
||||
'min_deposit' => 'decimal:8',
|
||||
'max_amount' => 'decimal:8',
|
||||
'starts_at' => 'datetime',
|
||||
'expires_at' => 'datetime',
|
||||
'rules' => 'array',
|
||||
];
|
||||
|
||||
public function scopeActive($query)
|
||||
{
|
||||
$now = now();
|
||||
return $query->where('status', 'active')
|
||||
->when($now, function ($q) use ($now) {
|
||||
$q->where(function ($qq) use ($now) {
|
||||
$qq->whereNull('starts_at')->orWhere('starts_at', '<=', $now);
|
||||
})->where(function ($qq) use ($now) {
|
||||
$qq->whereNull('expires_at')->orWhere('expires_at', '>=', $now);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user