lundi 2 octobre 2017

Sending new user password by mail notification

i have user controller with this store function

public function store(Request $request)
{  //Request validation etc...
    $user=new User();
    $user->numMembre=$numMembre;
    $user->nom=$nom;
    $user->prenom=$prenom;
    $user->sexe=$sexe;
    $user->email=$email;
    $user->password=bcrypt($password);

    $user->save();

    $user->notify(new PasswordNotification($password)); 

    return redirect()->route('back.admin.users.index')
        ->with('flash_message',
         'User successfully added.');
}

And the notification code

class PasswordNotification extends Notification implements ShouldQueue
{
use Queueable;

private $password;


public function __construct($password)
{
    $this->password=$password;
}


public function via($notifiable)
{
    return ['mail'];
}


public function toMail($notifiable)
{
    return (new MailMessage)
                ->view('back.admin.users.mail', compact('password'));
}

public function toArray($notifiable)
{
    return [
        //
    ];
}
}

but i got error cause by the password variable and even if i delete it, the mail isn't sent..



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire