2

I have a trait I use to send mails using mailgun PHP sdk, I'm getting the following error when I try to send mails:

 Trait 'App\Models\sendMailgunSdkApi' not found

This is my Discount model where I use the trait inside sendDiscountMail1 method,

<?php
namespace App\Models;


use Illuminate\Database\Eloquent\Model;
use App\Models\DiscountCode;
use App\Models\Order;
use Carbon\Carbon;
use App\Models\Scopes\Discounts;
use Mailgun\Mailgun;
use App\Traits\SendMail;


class Discount extends Model
{


    use Discounts, sendMailgunSdkApi;

      public static function sendMail1($order)
    {

        $mailData = 
        [
            'order' => $order
        ];

        $mail = $this->sendMailgunSdkApi('emails.discounts.discount-mail-1', $mailData, 'Disfruta de tu nuevo descuento en '.config('app.name').'.', '[email protected]');

        return response()->json([
            'mail' => $mail,
        ]);
    }


}

Why is it trying to look for a trait in my models folder?

My trait just in case:

<?php
namespace App\Traits;


trait SendMail
{


    public function sendMailgunSdkApi($view, $mailData, $subject, $to)
    {
        $html = view($view, compact('mailData'))->render();

        $result = app(Mailgun::class)->messages()->send(config('mail.mailgun.domain'), [
            'from' => config('mail.from.name').' <'.config('mail.from.address').'>',
            'to' => $to,
            'subject' => $subject,
            'html' => $html,
        ]);

        return $result;
    }




}

1 Answer 1

4

use SendMail as a trait and then call sendMailgunSdkApi function

use App\Traits\SendMail;

class Discount extends Model
{
    use Discounts,SendMail;

    public static function sendMail1($order)
    {

        $mailData = 
        [
            'order' => $order
        ];

        $mail = $this->sendMailgunSdkApi('emails.discounts.discount-mail-1', $mailData, 'Disfruta de tu nuevo descuento en '.config('app.name').'.', '[email protected]');

        return response()->json([
            'mail' => $mail,
        ]);
    }

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.