Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mhmmdva's avatar

how to fixed illegal Illegal offset type

I want to send email notifications to all reviewer type roles

 Mail::send('emails.proposal', ['data' => $data], function ($message) use ($data){
            $message->from('[email protected]', 'Administrator'); 
            $message->subject('upload file : ' . $data['title']);
            $message->to(auth()->user()->email)->cc(User::where('role', 'Reviewer')->get());
        });      
0 likes
3 replies
netconnect's avatar

Well, actually you this happens when you try to use a non-scalar value as an array key or index. So, first retrieve a list of reviewers. Make a loop for reviewers and add each reviewer to cc. Check it out:

Mail::send('emails.proposal', ['data' => $data], function ($message) use ($data) {
$message->from('[email protected]', 'Administrator');
$message->subject('upload file : ' . $data['title']);

// Query all users with the role 'Reviewer'
$reviewers = User::where('role', 'Reviewer')->get();

// Loop through the reviewers and add them to CC recipients
foreach ($reviewers as $reviewer) {
    $message->cc($reviewer->email);
}

// Add the sender's email as well, if needed
$message->cc(auth()->user()->email);

});

3 likes
tisuchi's avatar
tisuchi
Best Answer
Level 70

@mhmmdva I think it could be an alternative approach.

Mail::send('emails.proposal', ['data' => $data], function ($message) use ($data){
    $message->from('[email protected]', 'Administrator'); 
    $message->subject('upload file : ' . $data['title']);

    $reviewerEmails = User::where('role', 'Reviewer')->pluck('email')->toArray();

    $message->to(auth()->user()->email)->cc($reviewerEmails);
});
1 like

Please or to participate in this conversation.