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')
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?