fix: statisc
This commit is contained in:
@@ -60,4 +60,39 @@ final class AgentScope
|
||||
|
||||
return $devicesQuery->whereIn('devices.channel_id', $ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restrict a query that has a bare channel_id column (e.g. page_visits).
|
||||
*/
|
||||
public static function applyChannelIdScope(Builder $query, ?User $agent, string $column = 'channel_id'): Builder
|
||||
{
|
||||
if ($agent === null) {
|
||||
return $query;
|
||||
}
|
||||
|
||||
$ids = self::channelIdsFor($agent);
|
||||
if ($ids === []) {
|
||||
return $query->whereRaw('1 = 0');
|
||||
}
|
||||
|
||||
return $query->whereIn($column, $ids);
|
||||
}
|
||||
|
||||
public static function applyChannelIdAgentUserFilter(Builder $query, ?int $agentUserId, string $column = 'channel_id'): Builder
|
||||
{
|
||||
if ($agentUserId === null || $agentUserId <= 0) {
|
||||
return $query;
|
||||
}
|
||||
|
||||
$ids = Channel::query()
|
||||
->where('user_id', $agentUserId)
|
||||
->pluck('channel_id')
|
||||
->all();
|
||||
|
||||
if ($ids === []) {
|
||||
return $query->whereRaw('1 = 0');
|
||||
}
|
||||
|
||||
return $query->whereIn($column, $ids);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user