Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!
We spend hours on Instagram and YouTube and waste money on coffee and fast food, but wonβt spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!
Learn from Guru Rajesh Kumar and double your salary in just one year.
This is like this for your controller:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Illuminate\Foundation\Auth; | |
use Illuminate\Http\Request; | |
use Illuminate\Mail\Message; | |
use Illuminate\Support\Facades\Password; | |
class YourController extends Controller | |
{ | |
public function sendEmail() | |
{ | |
$credentials = ['email' => $email_address]; | |
$response = Password::sendResetLink($credentials, function (Message $message) { | |
$message->subject($this->getEmailSubject()); | |
}); | |
switch ($response) { | |
case Password::RESET_LINK_SENT: | |
return redirect()->back()->with('status', trans($response)); | |
case Password::INVALID_USER: | |
return redirect()->back()->withErrors(['email' => trans($response)]); | |
} | |
} | |
} |
I only added a token to his answer. this works just fine:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$user = User::where('email', request()->input('email'))->first(); | |
$token = Password::getRepository()->create($user); | |
$user->sendPasswordResetNotification($token); |
Complete control for Laravel 5.5:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$user = User::where('email', request()->input('email'))->first(); | |
$token = Password::getRepository()->create($user); | |
Mail::send(['text' => 'emails.password'], ['token' => $token], function (Message $message) use ($user) { | |
$message->subject(config('app.name') . ' Password Reset Link'); | |
$message->to($user->email); | |
}); |
The easiest way:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$token = Str::random(60); | |
$user = User::where('email', request()->input('email'))->first(); | |
$user->sendPasswordResetNotification($token); |
And if you want to edit your e-mail manually:
php artisan vendor:publish
Select β11β gives you:
/resources/views/vendor/notifications/email.blade.php
Use this code to send the password reset link. Here I am API Route for this.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$this->validate($request, [ | |
'user_id' => 'required|int', | |
]); | |
$user = User::find($request->user_id); | |
if( $user ) | |
{ | |
$credentials = ['email' => $user->email]; | |
$response = Password::sendResetLink($credentials, function (Message $message) { | |
$message->subject($this->getEmailSubject()); | |
}); | |
switch ($response) { | |
case Password::RESET_LINK_SENT: | |
return response()->json([ | |
'status' => 'success', | |
'message' => 'Password reset link send into mail.', | |
'data' =>''], 201); | |
case Password::INVALID_USER: | |
return response()->json([ | |
'status' => 'failed', | |
'message' => 'Unable to send password reset link.' | |
], 401); | |
} | |
} | |
return response()->json([ | |
'status' => 'failed', | |
'message' => 'user detail not found!' | |
], 401); |
for Web View :
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$response = Password::sendResetLink($credentials, function (Message $message) { | |
$message->subject($this->getEmailSubject()); | |
}); | |
switch ($response) { | |
case Password::RESET_LINK_SENT: | |
return redirect()->back()->with('status', trans($response)); | |
case Password::INVALID_USER: | |
return redirect()->back()->withErrors(['email' => trans($response)]); | |
} |