2016-12-30 5 views
5

인증 시스템에 대한 laravel 명령을 수행했습니다. php artisan make:auth 내 응용 프로그램에 대한 인증 시스템을 만들었고 거의 모든 것이 작동합니다.비밀 번호 재설정 대체 사용자 템플릿 laravel 5.3

잊어 버린 암호를 사용하여 내 메일 ID에 토큰을 보내면 템플릿에 laravel과 내가 편집하거나 ommit하고 싶은 다른 것들이 들어 있다는 것을 알았습니다. 정확하게 사용자 지정 템플릿을 원합니다. 거기에서 사용할 수 있습니다.

컨트롤러와 소스 파일을 보았지만 템플릿이나 메일에 html을 표시하는 코드를 찾을 수 없습니다.

어떻게해야합니까?

어떻게 변경합니까?

이것은 laravel에서 메일로 전송되는 기본 템플릿입니다. enter image description here

답변

4

단말기에서 다음 명령을 실행하면 두 개의 이메일 템플릿이 resources/vendor/notifications 폴더에 복사됩니다. 그런 다음 템플릿을 수정할 수 있습니다.

php artisan vendor:publish --tag=laravel-notifications 

당신은 Laravel DocsNotifications에 대한 자세한 내용을보실 수 있습니다.

+0

이메일 템플릿은 내부 자원/뷰/공급 업체/알림 폴더가 될 것입니다. – KCP

+0

전체 답변은 https://stackoverflow.com/a/41401524/2144424라고 생각합니다. – jpussacq

7

그냥 머리까지 : 당신이 통지 라인 등 You are receiving this... 같은을 수정하려면 이전의 대답에 추가하여, 다음을 단계별로 설명 추가 단계가 있습니다.

User 모델의 경우 override the defaultsendPasswordResetNotification 방법이 필요합니다.

왜? 선은 Illuminate\Auth\Notifications\ResetPassword.php에서 가져 왔기 때문입니다. 핵심 부분을 수정하면 Laravel을 업데이트하는 동안 변경 사항이 손실됩니다.

이렇게하려면 User 모델에 다음을 추가하십시오.

use App\Notifications\PasswordReset; // Or the location that you store your notifications (this is default). 

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

마지막으로, create that notification :

/** 
* The password reset token. 
* 
* @var string 
*/ 
public $token; 

/** 
* Create a new notification instance. 
* 
* @return void 
*/ 
public function __construct($token) 
{ 
    $this->token = $token; 
} 

/** 
* Get the notification's delivery channels. 
* 
* @param mixed $notifiable 
* @return array 
*/ 
public function via($notifiable) 
{ 
    return ['mail']; 
} 

/** 
* Build the mail representation of the notification. 
* 
* @param mixed $notifiable 
* @return \Illuminate\Notifications\Messages\MailMessage 
*/ 
public function toMail($notifiable) 
{ 
    return (new MailMessage) 
     ->line('You are receiving this email because we received a password reset request for your account.') // Here are the lines you can safely override 
     ->action('Reset Password', url('password/reset', $this->token)) 
     ->line('If you did not request a password reset, no further action is required.'); 
} 
+1

고마워요. 이것은 완전한 대답입니다. 전자 메일의 제목을 변경하려면 다음 줄 -> 제목 ('사용자 정의 제목')을 추가해야했습니다. 고마워. – jpussacq

0

당신은 또한 자신의 메일 템플릿을 구축하고 재설정을 사용하여 직접 링크를 전송하여이 작업을 수행 할 수 있습니다 :

php artisan make:notification PasswordReset 

그리고이 통지의 내용의 예 PHP mail() 또는 Laravel Mail Facade이지만 먼저 리셋 토큰

를 만들어야합니다.

1) use Illuminate\Contracts\Auth\PasswordBroker;

$user = User::where('email', $email)->first(); 
       if ($user) { 
        //so we can have dependency 
        $password_broker = app(PasswordBroker::class); 
        //create reset password token 
        $token = $password_broker->createToken($user); 

        DB::table('password_resets')->insert(['email' => $user->email, 'token' => $token, 'created_at' => new Carbon]); 

//Send the reset token with your own template 
//It can be like $link = url('/').'/password/reset/'.$token; 

       }