Ich versuche, Benachrichtigungs-und Mailgun-Service zum ersten Mal in Laravel zu verwenden. Ich benutze Laravel 5.4E-Mail-Benachrichtigung mit MailGun, Benachrichtigung senden - Laravel 5.4
Ich sehe Laravel 5.2 + kommt mit einer neuen Funktion namens Notification out of the box, die Password Reset etc. ganz gut behandelt.
So plant ich für folgende E-Mail an Benutzer senden:
1) Wenn Benutzer Register der zum ersten Mal
2) Wenn Benutzeranfragen nach einem Passwort
3) Wenn Benutzer zurückgesetzt meldet ein Problem
4) wenn Benutzer senden
5) Endlich eine Freundschafts-Anfrage ist, wenn der Benutzer eine Freundschaftsanfrage akzeptiert.
Ich bin ein wenig verwirrt und verlor den Überblick darüber, wie ich vorgehen soll. MailGun ist fertig und ich kann zu diesem Zeitpunkt eine Test-E-Mail an die Benutzer senden, indem ich Postman benutze, ohne die Benachrichtigung in das Bild zu bringen. Ich habe auch Notification Service eingerichtet und habe 2 Dinge an Ort und Stelle:
Ich verstehe nicht, wie Benachrichtigung und Mail zusammenarbeiten? Oder sollte ich bei jemandem bleiben?
Ich erhalte derzeit einen Fehler, wenn ich eine E-Mail in Passwort zurücksetzen Formular eingeben.
Fehler
ReflectionException in Container.php line 681:
Class App\Http\Controllers\ResetPasswordController does not exist
Formular
<form id="msform" role="form" method="POST" action="{{ url('/api/reset') }}">
{{ csrf_field() }}
<fieldset>
<h2 class="fs-title">Enter Password Reset Details</h2>
<h3 class="fs-subtitle">Easy as That !</h3>
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<div class="col-md-6">
<input id="email" type="email" class="form-control" name="email" placeholder="Email Address" value="{{ old('email') }}" required>
@if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group">
<input type="submit" name="submit" class="submit action-button" value="Reset"/>
</div>
</fieldset>
</form>
Routen
Route::post('api/reset', '[email protected]');
Controller-Resetpassword
public function send(Request $request)
{
$user = Auth::user()->email;
$user->notify(new WelcomeUser());
Mail::send('emails.passwordreset', function ($message)
{
$message->from('[email protected]', 'Admin - John Doe');
$message->to('[email protected]');
$message->subject('Password Reset');
});
return response()->json(['message' => 'Request completed']);
}
User-Modell
use Illuminate\Notifications\Notifiable;
public function routeNotificationForMail()
{
return $this->email;
}
Mitteilung
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
class WelcomeUser extends Notification
{
use Queueable;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct()
{
}
/**
* 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)
{
return (new MailMessage)
->line("Welcome User!")
->action('Let\'s Login', route('auth.login'))
->line("Let's get going!");
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
}