2017-02-14 28 views
1

Laravelで初めて通知および郵便サービスを使用しようとしています。私はLaravelを使用しています。5.4MailGun、通知 - Laravel 5.4を使用して電子メール通知を送信する

Laravel 5.2+には、パスワードリセットなどを処理するボックスからの通知という新機能があります。

は、だから私は、次のために、ユーザーに電子メールを送信することを計画しています:

1)時のユーザー登録者はパスワードのためのユーザーの要求が

3)時のユーザーをリセットする初めて

2)についてユーザーが友達リクエストを受け付け最後に、レポート問題

4)時のユーザーのセンドの友達リクエスト

5)。

これを進める方法について少し混乱し、迷っています。 MailGunはすべて設定されており、この時点でPostmanを使用して写真に通知を出さずにテスト電子メールを送信することができます。私は通知サービスをセットアップして、2つのものを用意しています:

通知とメールの連携の仕組みは分かりませんか?または私は誰にも固執する必要がありますか?

パスワードリセットフォームにメールを入力すると、現在エラーが発生しています。

エラー

ReflectionException in Container.php line 681: 
Class App\Http\Controllers\ResetPasswordController does not exist 

フォーム

<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> 

ルート

Route::post('api/reset', '[email protected]'); 

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モデル

use Illuminate\Notifications\Notifiable; 

public function routeNotificationForMail() 
{ 
    return $this->email; 
} 

通知

<?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 [ 
      // 
     ]; 
    } 
} 

答えて

0

あなたが一緒にメール通知やメールを使用することができ、確かに。通知では、ビューブレードファイルを作成する必要はありません。すべてのメール通知は、同じビューテンプレートを使用します。また、メールの一部をメール通知に置き換えることもできます。あなたの特定の実装については

Route::post('api/reset', 'Auth\[email protected]'); 

あなたのセンド()関数に置き換えるようまたPasswordResetControllerは、Auth::user()にアクセスすることはできません:あなたのルートにAuth\を追加し、あなたはLaravel認証足場コントローラを使用していると仮定すると、

最初の行は次のようになります。

$user = User::where('email', $request->email)->first(); 

WelcomeUser tificationあなたのルートからauth.を削除:

->action('Let\'s Login', route('login')) 

また、メールでの2番目のパラメータとして[]を追加します::()関数を送信します。

関連する問題