lundi 16 août 2021

Send notification Email with Laravel

i am creating a website to request appointments for the doctor,

public function crear(Request $request){

$this->validate($request, [
    'user_id'     =>  'required',
    'nombre'  =>  'required',
    'fecha' =>  'required',
    'hora' =>  'required',
    'telefono' =>  'required',
    'servicios_id' =>  'required',
   ]);

    Solicitudes::insert([
      'user_id'       => $request->input("user_id"),
      'telefono'  => $request->input("telefono"),
      'fecha'        => $request->input("fecha"),
      'hora'        => $request->input("hora"),
      'nombre'        => $request->input("nombre"),
      'servicios_id'        => $request->input("servicios_id"),
    ]);


// $pageName = 'widgets';
return redirect('solicitudes')->with('success', 'Solicitud Envíada exitosamente!');

}

need that when inserting the record to the database, send an email notification to the logged in user

I already have my notification created

 <?php
namespace App\Notifications;
 
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use App\Models\User;
 
class NewMessage extends Notification
{
    use Queueable;
    public $fromUser;
 
    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct(User $user)
    {
        $this->fromUser = $user;
    }
 
    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['mail'];
    }
 
    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        $subject = sprintf('%s: You\'ve got a new message from %s!', config('app.name'), $this->fromUser->name);
        $greeting = sprintf('Hola %s!', $notifiable->name);
 
        return (new MailMessage)
                    ->subject($subject)
                    ->greeting($greeting)
                    ->salutation('Atentamente Malker Sistemas')
                    ->line('Notificación de la empresa')
                    ->action('Ver Turno', url('/'))
                    ->line('Has solicitado Turno correctamente!');
    }
 
    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            //
        ];
    }
}

the problem is that i don't know how to send the notification when the record is inserted

help pls



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire