我试图通过API路由触发Laravel 5.5中的密码重置电子邮件,到目前为止我有这个控制器
<?php
namespace App\Http\Controllers\Api;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Response;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
class ForgotPasswordController extends Controller
{
use SendsPasswordResetEmails;
public function sendResetLinkEmail(Request $request) {
if($request->input('email')) {
$this->sendResetLinkEmail($request->input('email'));
}
/* Return Success Response */
return Response::json(array(
'error' => false,
'status_code' => 200,
'response' => 'forgotten_pass_request',
'email' => $request->input('email'),
));
}
}
但是当我尝试通过电子邮件发送API请求时,我收到了错误
"message": "Type error: Argument 1 passed to App\\Http\\Controllers\\Api\\ForgotPasswordController::sendResetLinkEmail() must be an instance of Illuminate\\Http\\Request, string given, called in /home/myapp/myapp/app/Http/Controllers/Api/ForgotPasswordController.php on line 23",
任何人都知道我做错了什么?
答案 0 :(得分:1)
将您的功能名称更改为其他名称
class ForgotPasswordController extends Controller
{
use SendsPasswordResetEmails;
public function changedTheName(Request $request) {
if($request->input('email')) {
$this->sendResetLinkEmail($request);
}
/* Return Success Response */
return Response::json(array(
'error' => false,
'status_code' => 200,
'response' => 'forgotten_pass_request',
'email' => $request->input('email'),
));
}
}
您的代码以递归方式调用自身。 你很高兴。
希望这个帮助