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 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号