-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Expand file tree
/
Copy pathMemberAccessScope.php
More file actions
35 lines (27 loc) · 912 Bytes
/
MemberAccessScope.php
File metadata and controls
35 lines (27 loc) · 912 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
declare(strict_types=1);
namespace App\Models\Scopes;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Scope;
use Illuminate\Support\Facades\DB;
use function is_string;
final class MemberAccessScope implements Scope
{
public function apply(Builder $builder, Model $model): void
{
$memberId = session('workspace_member') ?? context('workspace_member');
if (! is_string($memberId) || $memberId === '') {
return;
}
$scopeQuery = DB::table('workspace_member_scopes')
->where('workspace_member_id', $memberId)
->where('scopeable_type', $model->getMorphClass());
if ($scopeQuery->exists()) {
$builder->whereIn(
$model->qualifyColumn('id'),
$scopeQuery->select('scopeable_id'),
);
}
}
}