2017-03-03 15 views
3

私はLaravelのパスワードリセットメールをカスタマイズしようとしています。Laravelのパスワードを忘れた場合のカスタマイズ5.4

私は、この関数をオーバーライドする必要があります。

namespace Illuminate\Auth\Passwords; 

use Illuminate\Auth\Notifications\ResetPassword as ResetPasswordNotification; 
use Illuminate\Http\Request; 


trait CanResetPassword 
{ 
    /** 
    * Get the e-mail address where password reset links are sent. 
    * 
    * @return string 
    */ 
    public function getEmailForPasswordReset() 
    { 
     return $this->email; 
    } 

    /** 
    * Send the password reset notification. 
    * 
    * @param string $token 
    * @return void 
    */ 

public function sendPasswordResetNotification($token) 
{ 

    $this->notify(new ResetPasswordNotification($token)); 

} 

これは私の試みです:

public function sendPasswordResetNotification($token, Requests $request) 
{ 
Mail::to($request->email)->send(new newpassword($token)); 
} 

私はこのエラーを取得する:

Declaration of Illuminate\Foundation\Auth\User::sendPasswordResetNotification($token, Illuminate\Http\Request $request) must be compatible with Illuminate\Contracts\Auth\CanResetPassword::sendPasswordResetNotification($token)

+0

この答えをチェックアウトhttp://stackoverflow.com/questions/40574001/how-to-change-reset-password-email -ject-in-laravel –

答えて

4

エラーを読めば、それは言っていますあなたのクラスはCanResetPasswordと互換性がありません。あなたが見ることができますが、その見れば....

interface CanResetPassword 
{ 
    /** 
    * Get the e-mail address where password reset links are sent. 
    * 
    * @return string 
    */ 
    public function getEmailForPasswordReset(); 
    /** 
    * Send the password reset notification. 
    * 
    * @param string $token 
    * @return void 
    */ 
    public function sendPasswordResetNotification($token); 
} 

機能sendPasswordResetNotificationは一つのパラメータのみ、$tokenを取る必要があります。したがって、メソッドのシグネチャからパラメータとしてRequest $requestを削除する必要があります。

リクエストを取得するには、メソッド内でrequest()ファンクションを使用することをお勧めします。

public function sendPasswordResetNotification($token) 
{ 
    Mail::to(request()->email)->send(new newpassword($token)); 
} 
4

私は電子メールをカスタマイズするためにその長さに行くのに驚いています。

は、代わりにこれを試してみてください:

php artisan vendor:publish 

そして、私たちの使用のための素晴らしい作品

/resources/views/vendor/notifications/email.blade.php 
ここ

をファイルを変更します。

[email protected]:~/laravel_5.4$ php artisan vendor:publish 
Copied Directory [/vendor/laravel/framework/src/Illuminate/Pagination/resources/views] To [/resources/views/vendor/pagination] 
Copied Directory [/vendor/laravel/framework/src/Illuminate/Notifications/resources/views] To [/resources/views/vendor/notifications] 
Copied Directory [/vendor/laravel/framework/src/Illuminate/Mail/resources/views] To [/resources/views/vendor/mail] 
Publishing complete. 

は今、あなたはコピーを変更する必要がある場合、あなたは、元のResetPasswordのクラスが使用する空想ボタンは、次の例のように、あなたのUser.phpクラスにメールクラスを拡張することができますしたいです。ここで

は、例としてのみ素晴らしい作品私たちのコピーです:

<?php 

namespace App; 

use Illuminate\Foundation\Auth\User as Authenticatable; 
use Illuminate\Notifications\Notifiable; 
use Illuminate\Auth\Notifications\ResetPassword; 
use Illuminate\Notifications\Messages\MailMessage; 

class User extends Authenticatable 
{ 
    use Notifiable; 

    protected $table = 'Users'; 

    /** 
    * The attributes that are mass assignable. 
    * 
    * @var array 
    */ 
    protected $fillable = [ 
     'firstName', 
     'lastName', 
     'email', 
     'password', 
    ]; 

    /** 
    * The attributes that should be hidden for arrays. 
    * 
    * @var array 
    */ 
    protected $hidden = [ 
     'password', 'remember_token', 
    ]; 

    /** 
    * Sends the password reset notification. 
    * 
    * @param string $token 
    * 
    * @return void 
    */ 
    public function sendPasswordResetNotification($token) 
    { 
     $this->notify(new CustomPassword($token)); 
    } 
} 

class CustomPassword extends ResetPassword 
{ 
    public function toMail($notifiable) 
    { 
     return (new MailMessage) 
      ->line('We are sending this email because we recieved a forgot password request.') 
      ->action('Reset Password', url(config('app.url') . route('password.reset', $this->token, false))) 
      ->line('If you did not request a password reset, no further action is required. Please contact us if you did not submit this request.'); 
    } 
} 
関連する問題