CheckType::class, 'check_status' => CheckStatus::class, 'checked_at' => 'datetime:Y-m-d H:i:s', ]; public function check() { return $this->belongsTo(WorkflowCheck::class, 'check_id'); } public function checkUser() { return $this->belongsTo(Employee::class, 'check_user_id'); } public function scopeSort($q) { return $q->orderBy('batch_id', 'desc')->orderBy('sort', 'desc'); } public function scopeOwn($builder, $user) { $checkValue = [$user->id]; $userJobs = $user->jobs; if ($userJobs && $userJobs->count() > 0) { foreach($userJobs->unique('key') as $item) { array_push($checkValue, $user->store_id . '-' . $item->key); } } return $builder->whereIn('check_value', $checkValue); } }