0
votes

I am trying to trigger a password reset email in Laravel 5.5 through an API route, I have this controller so far

<?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'),
        ));

    }

}

But when i try and send an API request with email I get the error

"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",

Anyone any idea what I am doing wrong?

1
You have the answer in the error. You need a different route for apiIndra
If you look closely this function is calling itself in a recursive wayRomantic Dev

1 Answers

2
votes

Change the name of your function to something else then

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'),
        ));

    }

}

Your code is calling itself in a recursive way. You are then good to go.

Hope this help