2016-12-30 17 views
5

साथ पासवर्ड रीसेट की जगह मेल टेम्पलेट मैं प्रमाणीकरण प्रणाली के लिए laravel आदेश किया था, php artisan make:auth यह मेरी अनुप्रयोग के लिए प्रमाणीकरण प्रणाली बना दिया है और लगभग सब कुछ काम कर रहा है।कस्टम टेम्पलेट laravel 5.3

अब जब मैं भूल गया पासवर्ड का उपयोग करता हूं और यह मुझे मेरे मेल आईडी पर एक टोकन भेजता है, तो मुझे लगता है कि टेम्पलेट में लार्वेल और कुछ अन्य चीजें हैं जिन्हें मैं संपादित करना या छोड़ना चाहता हूं, सटीक होने के लिए, मैं अपना कस्टम टेम्पलेट चाहता हूं वहां इस्तेमाल किया जाना है।

मैं नियंत्रकों और उनके स्रोत फ़ाइलों को देखा, लेकिन मैं टेम्पलेट या कोड है कि मेल में एचटीएमएल प्रदर्शित कर रहा है नहीं मिल रहा।

मैं इसे कैसे करते हैं?

मैं इसे बदल सकता हूँ?

यह है कि laravel से मेल करने के लिए आता डिफ़ॉल्ट टेम्पलेट है। enter image description here

उत्तर

4

टर्मिनल में निम्न आदेश चलाएं और दो ईमेल टेम्पलेट्स को आपके संसाधन/विक्रेता/अधिसूचना फ़ोल्डर में कॉपी किया जाएगा। फिर आप टेम्पलेट्स को संशोधित कर सकते हैं।

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

आप Laravel Docs में Notifications के बारे में अधिक पढ़ सकते हैं।

+0

ईमेल टेम्पलेट के अंदर संसाधनों/विचारों/विक्रेता/सूचनाएं फ़ोल्डर हो जाएगा। – KCP

+0

मुझे लगता है कि पूरा जवाब https://stackoverflow.com/a/41401524/2144424 – jpussacq

7

बस एक सिर ऊपर: पिछले जवाब के अलावा, वहाँ अतिरिक्त कदम अगर आप अधिसूचना लाइनोंYou are receiving this... की तरह, आदि को संशोधित करना चाहते हैं नीचे एक कदम-दर-कदम गाइड है।

आपको अपने User मॉडल पर override the defaultsendPasswordResetNotification विधि की आवश्यकता होगी।

क्यों? क्योंकि लाइनें Illuminate\Auth\Notifications\ResetPassword.php से खींची जाती हैं। कोर में इसे संशोधित करने का अर्थ यह होगा कि लार्वेल के अपडेट के दौरान आपके परिवर्तन खो गए हैं।

ऐसा करने के लिए, अपने अपने 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:

php artisan make:notification PasswordReset 

और इस अधिसूचना की सामग्री का उदाहरण:

/** 
* 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 mail() या लार्वेल 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; 

       } 
संबंधित मुद्दे