public function search($search) { if (!empty($search)) { $users = $this->user->where('name', 'LIKE', '%' . $search . '%')->whereIn('role', array('coach', 'admin')); if ($users->count() > 0) { return $users->paginate(5); } else { $users = $this->user->where('email', 'LIKE', '%' . $search . '%')->whereIn('role', array('coach', 'admin')); return $users->paginate(5); } } }
public function search($search, $id) { if (!empty($search)) { $users = $this->user->select('name', 'entries.project_id as project_id', 'email', 'entries.id as id', 'frees.user_id as user_id')->join('entries', 'users.id', '=', 'entries.user_id')->join('frees', 'users.id', '=', 'frees.user_id')->where('users.name', 'LIKE', '%' . $search . '%')->where('entries.project_id', '=', $id); if ($users->count() > 0) { return $users->paginate(5); } else { $users = $this->user->select('name', 'entries.project_id as project_id', 'email', 'entries.id as id', 'frees.user_id as user_id')->join('entries', 'users.id', '=', 'entries.user_id')->join('frees', 'users.id', '=', 'frees.user_id')->where('users.email', 'LIKE', '%' . $search . '%')->where('entries.project_id', '=', $id); if ($users->count() > 0) { return $users->paginate(5); } } } }
public function create(array $data) { \DB::beginTransaction(); try { $password = bcrypt($data['password']); $user = User::create(['name' => mb_strtoupper($data['name']), 'email' => $data['email'], 'cpf' => $data['cpf'], 'identity' => $data['identity'], 'password' => $password]); $data['user_id'] = $user['id']; $birthdate = implode("-", array_reverse(explode("-", $data['birthdate']))); Client::create(['user_id' => $data['user_id'], 'birthdate' => $birthdate, 'phone' => $data['phone'], 'cel' => $data['cel'], 'gender' => $data['gender'], 'maritalstatus' => $data['maritalstatus'], 'mother' => mb_strtoupper($data['mother']), 'father' => mb_strtoupper($data['father']), 'nationality' => $data['nationality'], 'naturality' => $data['naturality'], 'children' => $data['children'], 'zipcode' => $data['zipcode'], 'address' => $data['address'], 'neighborhood' => $data['neighborhood'], 'complement' => $data['complement'], 'city' => $data['city'], 'state' => $data['state']]); $role = $this->roleRepository->find(5); $user->addRole($role); \DB::commit(); //$this->authService->passwordSend($data); } catch (\Exception $e) { \DB::rollback(); throw $e; } return $user; }