Skip to content

Commit

Permalink
Merge pull request #37 from JohnDivam/FIX-scopeForUser
Browse files Browse the repository at this point in the history
Refactor scopeForUser function
  • Loading branch information
alkrauss48 authored Oct 11, 2024
2 parents afac95e + c0e27b4 commit cf2f0e3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
12 changes: 5 additions & 7 deletions app/Models/DailyView.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,11 @@ public function scopeStats(Builder $query, ?string $presentationId = null): void
*/
public function scopeForUser(Builder $query): void
{
if (auth()->user()->isAdministrator()) {
return;
}

$presentationIds = auth()->user()->presentations()->pluck('id');

$query->whereIn('presentation_id', $presentationIds);
$query->when(!auth()->user()->isAdministrator(), function($qr){
$qr->whereHas('presentation', function($qrPresn){
$qrPresn->where('user_id',auth()->id());
});
});
}

/**
Expand Down
10 changes: 3 additions & 7 deletions app/Models/Presentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,9 @@ protected function shouldTrackView(): Attribute
*/
public function scopeForUser(Builder $query): void
{
if (auth()->user()->isAdministrator()) {
return;
}

$presentationIds = auth()->user()->presentations()->pluck('id');

$query->whereIn('id', $presentationIds);
$query->when(!auth()->user()->isAdministrator(), function($qr){
$qr->where('user_id',auth()->id());
});
}

/**
Expand Down

0 comments on commit cf2f0e3

Please sign in to comment.