Skip to content

Commit

Permalink
Changed separate mehod approved to approved and approvedOrOwner
Browse files Browse the repository at this point in the history
  • Loading branch information
tabuna committed Jul 28, 2024
1 parent 67a4bf2 commit 01327bc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/PositionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class PositionsController extends Controller
*/
public function jobs()
{
$positions = Position::approved()
$positions = Position::approvedOrOwner()
->with(['author'])
->whereDate('created_at', '>=', now()->subMonths(2))
->orderBy('id', 'desc')
Expand Down
17 changes: 15 additions & 2 deletions app/Models/Concerns/Approvable.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,21 @@ trait Approvable
*/
public function scopeApproved(Builder $query, bool $approved = true): Builder
{
return $query->where('approved', $approved)
->orWhere('user_id', auth()->id());
return $query->where('approved', $approved);
}


/**
* Scope a query to only include approved or owner items.
*
* @param Builder $query
* @param bool $approved
*
* @return Builder
*/
public function scopeApprovedOrOwner(Builder $query, bool $approved = true): Builder
{
return $query->approved($approved)->orWhere('user_id', auth()->id());
}

/**
Expand Down

0 comments on commit 01327bc

Please sign in to comment.