Forked from nasrulhazim/ForgotPasswordController.php
Created
December 13, 2018 10:19
-
-
Save miyasinarafat/4f605939160c3e13021d2c07ec6c7970 to your computer and use it in GitHub Desktop.
Laravel: Forgot Password Controller for API
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 | |
Route::post('forgot/password', 'ForgotPasswordController')->name('forgot.password') |
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 App\Http\Controllers\Api\Auth; | |
use App\Http\Controllers\Controller; | |
use Illuminate\Http\Request; | |
use Illuminate\Foundation\Auth\SendsPasswordResetEmails; | |
use Illuminate\Support\Facades\Password; | |
class ForgotPasswordController extends Controller | |
{ | |
use SendsPasswordResetEmails; | |
/** | |
* Create a new controller instance. | |
*/ | |
public function __construct() | |
{ | |
$this->middleware('guest'); | |
} | |
public function __invoke(Request $request) | |
{ | |
$this->validateEmail($request); | |
// We will send the password reset link to this user. Once we have attempted | |
// to send the link, we will examine the response then see the message we | |
// need to show to the user. Finally, we'll send out a proper response. | |
$response = $this->broker()->sendResetLink( | |
$request->only('email') | |
); | |
return $response == Password::RESET_LINK_SENT | |
? response()->json(['message' => 'Reset link sent to your email.', 'status' => true], 201) | |
: response()->json(['message' => 'Unable to send reset link', 'status' => false], 401); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment