feat(model): menambahkan scope
This commit is contained in:
parent
6345a3f388
commit
e7f5efb0cf
@ -3,6 +3,8 @@
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\Gender;
|
||||
use Illuminate\Database\Eloquent\Attributes\Scope;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
@ -23,6 +25,18 @@ protected function casts(): array
|
||||
];
|
||||
}
|
||||
|
||||
#[Scope]
|
||||
public function today(Builder $query): void
|
||||
{
|
||||
$query->whereDate('created_at', today());
|
||||
}
|
||||
|
||||
#[Scope]
|
||||
public function yesterday(Builder $query): void
|
||||
{
|
||||
$query->whereDate('created_at', today()->subDay());
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
|
||||
@ -3,6 +3,8 @@
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\ExpenseType;
|
||||
use Illuminate\Database\Eloquent\Attributes\Scope;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
@ -23,6 +25,18 @@ protected function casts(): array
|
||||
];
|
||||
}
|
||||
|
||||
#[Scope]
|
||||
public function today(Builder $query): void
|
||||
{
|
||||
$query->whereDate('created_at', today());
|
||||
}
|
||||
|
||||
#[Scope]
|
||||
public function yesterday(Builder $query): void
|
||||
{
|
||||
$query->whereDate('created_at', today()->subDay());
|
||||
}
|
||||
|
||||
public function outlet(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Outlet::class);
|
||||
|
||||
@ -40,6 +40,18 @@ public function paid(Builder $query): void
|
||||
$query->where('status', OrderStatus::PAID->value);
|
||||
}
|
||||
|
||||
#[Scope]
|
||||
public function today(Builder $query): void
|
||||
{
|
||||
$query->whereDate('created_at', today());
|
||||
}
|
||||
|
||||
#[Scope]
|
||||
public function yesterday(Builder $query): void
|
||||
{
|
||||
$query->whereDate('created_at', today()->subDay());
|
||||
}
|
||||
|
||||
public function outlet(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Outlet::class);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user