0

I am new at laravel. I am trying to send an email to a user. All data is successfully inserted except roles and I am getting an error below. How can I solve this issue ?

Error

 "message": "htmlspecialchars() expects parameter 1 to be string, array given (View: /home/developer/htdocs/yourstitichart/yourstitichart.pk/mycms/resources/views/user_email/user-email.blade.php)",

https://ibb.co/Qr5NZQt

UserController

public function createUser(Request $request)
  { 
  
    if ($request->id != 1) {
      $user['name'] = $request->name;
      if ($request->password) {
        $user['password'] = Hash::make($request->password);
      }
      $user['email'] = $request->email;
      $user = User::updateOrCreate(['id' => $request->id], $user);
      $user->syncRoles($request->roles);

      Mail::send(new UserEmail($request));
    }
  }

Mail/UserEMail

public function build()
    {
        return $this->subject('Wellcome To Yourstitichart')
        ->from($this->email->email, $this->email->name)
        ->cc($this->email)
        ->to(config('yourstitchart.mail_to'))
        ->view('user_email.user-email');
    }

resources/views/user_email/user-email.blade.php

       <tr>                                                                                                                                                                                                       
        <td style="padding: 5px 0" width="20%" align="left">
                                                                                                    
              <p>User Name :-      {{$email->name}}</p>
                                                                                                    
              <p>Email     :-      {{$email->email}}</p>
                                                                                                    
              <p>Designation :-    {{$email->roles}}</p>
                                                                                                    
               <p>Password :-       {{$email->password}}</p>
                                                                                        
             </td>
                                                                                            </tr>

response here

{"name":"demo","password":"KHI786786","email":"abc@gmail.com","roles":["Designer"],"id":46}
Al-Amin
  • 596
  • 3
  • 16
Zubair Mukhtar
  • 320
  • 1
  • 11
  • I guess it is because in your blade template you put 'roles' which is an array into {{}} which accepts only string. – Naco Oct 25 '20 at 09:28