Skip to content
This repository was archived by the owner on Aug 20, 2023. It is now read-only.

Commit 27ab862

Browse files
Added new scope methods
1 parent 2b3ffa8 commit 27ab862

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

README_TR.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,17 @@ Permission::where('id', $permission_id)->update([
7878
Permission::destroy($permission_id);
7979
Permission::destroy([1,2,3]); // birden fazla permission id'ler ile silme
8080
```
81+
#### Role isimlerine göre kullanıcıları alma
82+
```role()``` metoduyla sadece belirttiğiniz role sahip kullanıcıları alırken, ```exceptRole()``` metoduyla belirttiğiniz roller dışındaki tüm kullanıcıları alabilirsiniz. Rol isim veya isimleri her zaman ```array``` içinde tanımlanmalıdır.
8183

82-
> Aşağıda kullanılan rol ve yetki isimleri sadece örnektir. CRUD işlemleri ile kendi oluşturduğunuz rol ve yetki isimlerini kullanmalısınız. Rol ve yetki sorgulamaları için '**slug**' bilgisi ölçüt alınır.
84+
```php
85+
<?php
86+
User::role(['admin'])->get();
87+
User::role(['admin', 'editor'])->get();
88+
89+
User::exceptRole(['admin'])->get();
90+
User::exceptRole(['editor', 'customer'])->get();
91+
```
8392

8493
#### Rol ve Yetki Sorgulama
8594
Tüm sorgulama metotları her zaman bool (true/false) döner. Aşağıdaki örnekler PHP kodları içinde kullanılır.

Traits/CrewTrait.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,34 @@ private function roleCollection($roles): object
7878
});
7979
}
8080

81+
/**
82+
*
83+
* @param \Illuminate\Database\Eloquent\Builder $query
84+
* @param array $name
85+
*
86+
* @return \Illuminate\Database\Eloquent\Builder
87+
*/
88+
public function scopeRole($query, array $name)
89+
{
90+
return $query->whereHas("roles", function($roles) use($name) {
91+
$roles->whereIn("roles.slug", Arr::flatten($name));
92+
});
93+
}
94+
95+
/**
96+
*
97+
* @param \Illuminate\Database\Eloquent\Builder $query
98+
* @param array $name
99+
*
100+
* @return \Illuminate\Database\Eloquent\Builder
101+
*/
102+
public function scopeExceptRole($query, array $name)
103+
{
104+
return $query->whereHas("roles", function($roles) use($name) {
105+
$roles->whereNotIn("roles.slug", Arr::flatten($name));
106+
});
107+
}
108+
81109
/**
82110
*
83111
*/

0 commit comments

Comments
 (0)