@@ 48-63 (lines=16) @@ | ||
45 | * |
|
46 | * @return \Illuminate\Database\Eloquent\Builder |
|
47 | */ |
|
48 | public function scopeRole(Builder $query, $roles, $guard = null): Builder |
|
49 | { |
|
50 | if ($roles instanceof Collection) { |
|
51 | $roles = $roles->all(); |
|
52 | } |
|
53 | ||
54 | if (! is_array($roles)) { |
|
55 | $roles = [$roles]; |
|
56 | } |
|
57 | ||
58 | $roles = $this->getArgumentRoles($roles, $guard); |
|
59 | ||
60 | return $query->whereHas('roles', function (Builder $subQuery) use ($roles) { |
|
61 | $subQuery->whereIn(config('permission.table_names.roles').'.id', \array_column($roles, 'id')); |
|
62 | }); |
|
63 | } |
|
64 | ||
65 | /** |
|
66 | * Scope the model query without certain roles. |
|
@@ 74-89 (lines=16) @@ | ||
71 | * |
|
72 | * @return \Illuminate\Database\Eloquent\Builder |
|
73 | */ |
|
74 | public function scopeWithoutRole(Builder $query, $roles, $guard = null): Builder |
|
75 | { |
|
76 | if ($roles instanceof Collection) { |
|
77 | $roles = $roles->all(); |
|
78 | } |
|
79 | ||
80 | if (! is_array($roles)) { |
|
81 | $roles = [$roles]; |
|
82 | } |
|
83 | ||
84 | $roles = $this->getArgumentRoles($roles, $guard); |
|
85 | ||
86 | return $query->whereDoesntHave('roles', function (Builder $subQuery) use ($roles) { |
|
87 | $subQuery->whereIn(config('permission.table_names.roles').'.id', \array_column($roles, 'id')); |
|
88 | }); |
|
89 | } |
|
90 | ||
91 | /** |
|
92 | * Assign the given role to the model. |