doujiu3095 2018-08-13 13:58
浏览 219
已采纳

从单列数组laravel获取id

I have DB like this

|id|      email     |departement_id|
|1 |test1@gmail.com |1,2           |
|2 |test2@gmail.com |3,4           |
|3 |test3@gmail.com |5,1           |
|4 |test4@gmail.com |2,6           |

I trying to get id data for send email, from departement_id. If from request POST departement_id is 2, so the id must 1 and 4. How can I get the id in Laravel? because the data in single column-departement_id-is array.

this is my send email function...

Mail::send('mails.thanks',['ticket'=>$request, 'department' => $department], function ($message) use ($departement){
                $message->from(Config::get('const.email'), 'Ticket Plus');
                $message->subject('Nueva tarea creada');

                // get id user and send email user
                $getUsers = User::where('department_id',  [(int)$departement])->pluck('id')->toArray();
                $role_users = DB::table('role_user')
                             ->whereIn('user_id', $getUsers)
                             ->where('role_id', 2)
                             ->pluck('user_id')
                             ->toArray();
                $getMailUsers = DB::table('users')
                             ->whereIn('id', $role_users)
                             ->pluck('email')
                             ->toArray();

                foreach ($getMailUsers as $getMailUser)
                {
                    $message->to($getMailUser);
                };
                // $message->to($settings->admin_email);
            });

Thanks a lot..

  • 写回答

1条回答 默认 最新

  • dre93205 2018-08-13 14:14
    关注
    Users = User::whereRaw('FIND_IN_SET('.(int)$departement.', department_id) > 0')
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)