2016-11-13 6 views
10

मैं लार्वेल में शुरुआत कर रहा हूं। वर्तमान में मैं इस ढांचे को सीख रहा हूं। मेरा इलाज लारवेल संस्करण 5.3 है।लार्वेल में रीसेट पासवर्ड ईमेल विषय कैसे बदलें?

मैं php artisan make:auth का उपयोग करके अपने लेख को मचान कर रहा हूं सभी ठीक काम कर रहे हैं। इसके अलावा मैंने कॉन्फ़िगरेशन डायरेक्टोरी में मेरी .env फ़ाइल और mail.php में जीमेल smtp कॉन्फ़िगर किया। सब पूरी तरह से काम कर रहे हैं। लेकिन मैंने डिफ़ॉल्ट रूप से देखा पासवर्ड भूल गया ईमेल विषय Reset Password जा रहा है। मैं वह बदलना चाहता हूँ।

मैंने कुछ ब्लॉग देखा। मुझे कुछ ब्लॉग मिला। मैंने अपनी साइट पर इसे लागू किया है। लेकिन एक ही आउटपुट आ रहा है।

https://laracasts.com/discuss/channels/general-discussion/laravel-5-password-reset-link-subject

https://laracasts.com/discuss/channels/general-discussion/reset-password-email-subject

https://laracasts.com/discuss/channels/laravel/how-to-override-message-in-sendresetlinkemail-in-forgotpasswordcontroller

उत्तर

25

आप अपना पासवर्ड रीसेट ईमेल विषय बदल सकते हैं, लेकिन इसे कुछ अतिरिक्त काम की आवश्यकता होगी। सबसे पहले, आपको ResetPassword अधिसूचना का अपना कार्यान्वयन बनाना होगा। पेस्ट कॉपी-

php artisan make:notification ResetPassword 

या आप बस कर सकते हैं:

app\Notifications निर्देशिका के अंदर एक नई अधिसूचना कक्षा बनाएं, चलो यह ResetPassword.php नामित करते हैं:

<?php 

namespace App\Notifications; 

use Illuminate\Notifications\Notification; 
use Illuminate\Notifications\Messages\MailMessage; 

class ResetPassword extends Notification 
{ 
    public $token; 

    public function __construct($token) 
    { 
     $this->token = $token; 
    } 

    public function via($notifiable) 
    { 
     return ['mail']; 
    } 

    public function toMail($notifiable) 
    { 
     return (new MailMessage) 
      ->subject('Your Reset Password Subject Here') 
      ->line('You are receiving this email because we received a password reset request for your account.') 
      ->action('Reset Password', url('password/reset', $this->token)) 
      ->line('If you did not request a password reset, no further action is required.'); 
    } 
} 

तुम भी कारीगर आदेश का उपयोग अधिसूचना टेम्पलेट उत्पन्न कर सकते हैं उपरोक्त कोड। जैसा कि आप देख सकते हैं कि यह अधिसूचना वर्ग डिफ़ॉल्ट Illuminate\Auth\Notifications\ResetPassword के साथ बहुत समान है। आप वास्तव में इसे डिफ़ॉल्ट ResetPassword कक्षा से बढ़ा सकते हैं।

फर्क सिर्फ इतना है यहाँ है, आप ईमेल का विषय परिभाषित करने के लिए एक नई विधि कॉल जोड़ें:

return (new MailMessage) 
     ->subject('Your Reset Password Subject Here') 

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

दूसरी बात, आपके app\User.php फ़ाइल पर, आपको Illuminate\Auth\Passwords\CanResetPassword विशेषता द्वारा परिभाषित डिफ़ॉल्ट sendPasswordResetNotification() विधि को ओवरराइड करने की आवश्यकता है।

<?php 

namespace App; 

use Illuminate\Notifications\Notifiable; 
use Illuminate\Foundation\Auth\User as Authenticatable; 
use App\Notifications\ResetPassword as ResetPasswordNotification; 

class User extends Authenticatable 
{ 
    use Notifiable; 

    ... 

    public function sendPasswordResetNotification($token) 
    { 
     // Your your own implementation. 
     $this->notify(new ResetPasswordNotification($token)); 
    } 
} 

और अब आपके कूटशब्द पुनर्स्थापन ईमेल विषय अद्यतन किया जाना चाहिए: अब आप अपने खुद के ResetPassword कार्यान्वयन का उपयोग करना चाहिए!

Reset password email subject updated

आशा इस मदद!

+0

और हम शीर्ष पर लिखे गए लैरवेल और लैरवेल के संबंध में कैसे बदल सकते हैं। – Steve

+1

@Steve config/app.php पर जाएं और एप्लिकेशन का नाम बदलें – kniteli

1

आप आसानी से अधिसूचना उपयोगकर्ता के लिए पासवर्ड रीसेट लिंक भेजने के लिए इस्तेमाल वर्ग को संशोधित कर सकते -

मैं इन लिंक का अनुसरण। प्रारंभ करने के लिए, अपने उपयोगकर्ता मॉडल पर sendPasswordResetNotification विधि ओवरराइड करें। इस विधि के भीतर, आप अपने द्वारा चुने गए किसी भी अधिसूचना वर्ग का उपयोग करके अधिसूचना भेज सकते हैं। पासवर्ड रीसेट $token विधि द्वारा प्राप्त पहला तर्क है, देखें Doc for Customization

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

आशा इस मदद करता है!

+0

स्वीकार्य एक बहुत आसान है ..! –

2

आप एक कस्टम फ़ंक्शन बना सकते हैं जो इस तरह रीसेट पासवर्ड टोकन बनाएगा।

$user = User::where('email', '[email protected]')->first(); 
$password_broker = app(PasswordBroker::class); //so we can have dependency injection 
$token = $password_broker->createToken($user); //create reset password token 
$password_broker->emailResetLink($user, $token, function (Message $message) { 
     $message->subject('Custom Email title'); 
});//send email. 
0

बस पंक्ति जोड़ें: -

फ़ाइल रोशन \ प्रमाणीकरण \ सूचनाएं की विधि toMail \ ResetPassword इस तरह में> विषय ('नई Subjetc')

:

public function toMail($notifiable) 
{ 
    return (new MailMessage) 
     ->subject('New Subjetc') 
     ->line('You are receiving this email because we received a password reset request for your account.') 
     ->action('Restaurar Contraseña', url(config('app.url').route('password.reset', $this->token, false))) 
     ->line('If you did not request a password reset, no further action is required.'); 
} 
संबंधित मुद्दे