Skip to content

Commit

Permalink
Added the ofUser scope to the order model
Browse files Browse the repository at this point in the history
  • Loading branch information
fulopattila122 committed Apr 19, 2023
1 parent c8cae5d commit f77491d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## 3.x Series

## Unreleased
##### 2023-XX-YY

- Added the `ofUser()` scope to the base Order model

## 3.7.0
##### 2023-04-04

Expand Down
6 changes: 6 additions & 0 deletions Models/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
* @property OrderItem[]|Collection $items
* @method static static create(array $attributes = [])
* @method static Builder open()
* @method static Builder ofUser(User|int|string $user)
*/
class Order extends Model implements OrderContract
{
Expand Down Expand Up @@ -146,6 +147,11 @@ public function scopeOpen(Builder $query)
return $query->whereIn('status', OrderStatusProxy::getOpenStatuses());
}

public function scopeOfUser($query, $user)
{
return $query->where('user_id', is_object($user) ? $user->id : $user);
}

protected static function booted()
{
static::creating(function ($order) {
Expand Down

0 comments on commit f77491d

Please sign in to comment.