-
app/Traits/CanFilterByUser.php
Open in GitHubuse Illuminate\Database\Eloquent\Builder; trait CanFilterByUser { public function scopeByCurrentUser(Builder $query): Builder { return $query->where('user_id', auth()->user()->id); } }
-
app/Repositories/PlaylistRepository.php
Open in GitHubuse App\Repositories\Traits\ByCurrentUser; use Illuminate\Support\Collection; class PlaylistRepository extends AbstractRepository { use ByCurrentUser; public function getAllByCurrentUser(): Collection { return $this->byCurrentUser()->orderBy('name')->get(); } }