本文整理汇总了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);
}
}