2017-03-03 3 views
3

Laravel에서 암호 재설정 전자 메일을 사용자 지정하려고합니다. 오류를 읽는다면, 그것은잊어 버린 암호 사용자 지정 Laravel의 전자 메일 5.4

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 : 여기

은 단지 예를 위대한 작품을 우리의 사본입니다 -subject-in-laravel –

답변

4

을 말하고 :

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

내가이 오류 :이 내 시도

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

} 

:

나는이 함수를 재정의해야 귀하의 클래스는 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을 제거해야합니다.

요청을 받으려면 함수를 sendPasswordResetNotification 메서드 내부에서 사용하고 싶을 것입니다.

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.'); 
    } 
} 
관련 문제