Abed Putra
Abed Putra

Reputation: 1215

Get id from single column array laravel

I have DB like this

|id|      email     |departement_id|
|1 |[email protected] |1,2           |
|2 |[email protected] |3,4           |
|3 |[email protected] |5,1           |
|4 |[email protected] |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..

Upvotes: 0

Views: 254

Answers (1)

Alex
Alex

Reputation: 17289

Users = User::whereRaw('FIND_IN_SET('.(int)$departement.', department_id) > 0')

Upvotes: 3

Related Questions