123456789101112131415161718192021222324252627282930 |
- <?php
- namespace App\Scopes;
- use App\Model\Employee;
- use Illuminate\Database\Eloquent\Builder;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Scope;
- class DepartmentScope implements Scope
- {
- public $user = [];
- public function __construct($user = [])
- {
- $this->user = $user;
- }
- public function apply(Builder $builder, Model $model)
- {
- if($this->user['id'] != Employee::SPECIAL_ADMIN) {
- $depart_id = $this->user['depart_range'];
- $user_id = $this->user['id'];
- $builder->where(function ($query) use ($depart_id,$user_id){
- $query->whereIn('depart_id', $depart_id)
- ->orWhereIn('top_depart_id',$depart_id)
- ->orWhere('crt_id', $user_id);
- });
- }
- }
- }
|