| 123456789101112131415161718192021222324252627282930313233 | 
							- <?php
 
- namespace App\Scopes;
 
- use Illuminate\Database\Eloquent\Builder;
 
- use Illuminate\Database\Eloquent\Model;
 
- use Illuminate\Database\Eloquent\Scope;
 
- class DepartmentScope implements Scope
 
- {
 
-     public $depart_id = [];
 
-     public $is_main = 0;
 
-     public $user_id = 0;
 
-     public function __construct($depart_id = [], $is_main = 0, $user_id = 0)
 
-     {
 
-         if(! is_array($depart_id)) $depart_id = [$depart_id];
 
-         $this->depart_id = $depart_id;
 
-         $this->is_main = $is_main;
 
-         $this->user_id = $user_id;
 
-     }
 
-     public function apply(Builder $builder, Model $model)
 
-     {
 
-         if(! $this->is_main) {
 
-             $depart_id = $this->depart_id;
 
-             $user_id = $this->user_id;
 
-             $builder->where(function ($query) use ($depart_id,$user_id){
 
-                 $query->whereIn('depart_id', $depart_id)
 
-                     ->orWhere('crt_id', $user_id);
 
-             });
 
-         }
 
-     }
 
- }
 
 
  |