当前位置: 首页>>代码示例>>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;未经允许,请勿转载。