當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Department::worker方法代碼示例

本文整理匯總了PHP中app\Department::worker方法的典型用法代碼示例。如果您正苦於以下問題:PHP Department::worker方法的具體用法?PHP Department::worker怎麽用?PHP Department::worker使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app\Department的用法示例。


在下文中一共展示了Department::worker方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: store

 public function store(DepartmentRequest $request)
 {
     $allWorker = DB::table('department_worker')->get(['user_id']);
     $duplicateWorker = [];
     $leader = $request->department_leader;
     $departmentUsers = $request->department_worker;
     array_push($departmentUsers, $request->department_leader);
     $departmentUsers = array_unique($departmentUsers);
     foreach ($allWorker as $aw) {
         if (in_array($aw->user_id, $request->department_worker)) {
             array_push($duplicateWorker, $aw->user_id);
         }
     }
     if (!empty($duplicateWorker)) {
         $users = User::whereIn('id', $duplicateWorker)->select(DB::raw('CONCAT(first_name," ",last_name) as full_name'))->get();
         $usersString = '';
         foreach ($users as $u) {
             $usersString .= $u->full_name . ',';
         }
         return response()->json(['messages' => $usersString . ' Kişileri Başka Bir Departmana Bağlıdır.'], 422);
     } else {
         foreach ($departmentUsers as $key => $value) {
             $value == $leader ? $departmentUsers[$key] = ['user_id' => $value, 'is_senior' => 1] : ($departmentUsers[$key] = ['user_id' => $value, 'is_senior' => 0]);
         }
         $this->permissionSection(function () use($request, $departmentUsers) {
             DB::transaction(function () use($request, $departmentUsers) {
                 $department = new Department();
                 $department->slug = $request->slug_name;
                 $department->name = $request->department_name;
                 $department->save();
                 $department->worker()->sync($departmentUsers);
             });
         }, 'wts.department.create');
         return response()->json($this->storeResponseMessage);
     }
 }
開發者ID:pinnaclesoftware,項目名稱:Work-Tracking-System,代碼行數:36,代碼來源:DepartmentController.php


注:本文中的app\Department::worker方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。