Debug School

rakesh kumar
rakesh kumar

Posted on

Laravel Error:Too few arguments to function App\Mail\InfluencerMail::__construct(), 1 passed in paymentController.php

Error:Too few arguments to function App\Mail\InfluencerMail::__construct(), 1 passed in paymentController.php

my code
in conroller

       $influencernamedata = addcart::where('influencer_email', $email)->first();
        log::info($influencernamedata);
        log::info($email);
        $influencername=$influencernamedata->slug;
        log::info($influencername);
        $InfluencerMailsend = array(
            'name' =>$influencername,
            'email' => $email,
            'token' => $validToken,
        );
        log::info($InfluencerMailsend);
        Mail::to($InfluencerMailsend['email'])->send(new InfluencerMail($InfluencerMailsend));
        log::info("done");
Enter fullscreen mode Exit fullscreen mode

In Model

 public function __construct($InfluencerMailsend,$validToken)
    {
        $this->InfluencerMailsend = $InfluencerMailsend;
        $this->validToken = $validToken;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()  
    {
        return $this
        ->from('contact@wizbrand.com')
        ->subject('Welcome to WizBrand.com | Verification Email for sign-up!')
        ->view('emails.influencermail')
        ->with('data',$this->InfluencerMailsend,$this->validToken);
    }
Enter fullscreen mode Exit fullscreen mode

SOLUTION

Based on the screenshot you sent, the error message is telling you that the constructor for the InfluencerMail class expects 2 arguments, but you are only passing in 1 argument on line 101 of the paymentController.php file.

To fix this error, you need to pass in the second argument to the constructor. It looks like you are trying to send the $InfluencerMailsend array to the constructor, but you are only passing in the $email variable.

You can fix this by changing in controller

Mail::to($InfluencerMailsend['email'])->send(new InfluencerMail($InfluencerMailsend, $validToken));
Enter fullscreen mode Exit fullscreen mode

Illuminate\Support\Facades\Mail;

class

PaymentController

extends

Controller

{
    public

function store(Request $request)
    {
        // Validate the request.

        // Get the influencer email addresses.
        $influencer_emails = $request->input('influencer_emails');

        // Get the valid token.
        $validToken = $request->input('validToken');

        // Create an array of influencer data.
        $influencerMailsend = [];
        foreach ($influencer_emails as $email) {
            $influencernamedata = AddCart::where('influencer_email', $email)->first();

            $influencerMailsend[] = [
                'influencername' => $influencernamedata->slug,
                'email' => $email,
                'token' => $validToken,
            ];
        }

        // Send the email to the influencers.
        foreach ($influencerMailsend as $influencerData) {
            Mail::to($influencerData['email'])->send(new InfluencerMail($influencerData, $validToken));
        }

        // Return a success response.
        return response()->json(['success' => true]);
    }
Enter fullscreen mode Exit fullscreen mode

Image description

Top comments (0)