s-ichikawa / laravel-sendgrid-driver

This library can add sendgrid driver into the laravel's mail configure.
MIT License
391 stars 91 forks source link

undefined method App\Mail\SendTwenty::sendgrid() #101

Closed burmkiller closed 5 years ago

burmkiller commented 5 years ago

I've been gettting this error

undefined method App\Mail\SendTwenty::sendgrid()

currently I'm just doing this:

public function build() { return $this->from($this->domain_data[0]->email) ->subject("Your report is ready!") ->view('emails.twentyemail') ->sendgrid(['custom_args' => ['user_id' => $this->car_data[0]->id]]); }

Now I'm not sure where I went wrong, I've followed the installation process but doesn't seem like it's working for some reason.

s-ichikawa commented 5 years ago

Did you write use SendGrid;?

sample: https://github.com/s-ichikawa/laravel57/blob/master/app/Mail/ApiSimpleMailable.php#L13

burmkiller commented 5 years ago

Yes, I've called the class and I'm still getting this

Call to undefined method App\Mail\SendTwenty::sendgrid()

s-ichikawa commented 5 years ago

hum... write use Sichikawa\LaravelSendgridDriver\SendGrid; too?

sample: https://github.com/s-ichikawa/laravel57/blob/master/app/Mail/ApiSimpleMailable.php#L9

burmkiller commented 5 years ago

I've tried both of them yet it's still giving me the same error, I'm using this in my mailable class, it should work just fine.

s-ichikawa commented 5 years ago

What version is your laravel-sendgrid-driver? Is there sendgrid function in vendor/s-ichikawa/laravel-sendgrid-driver/src/SendGrid.php?

burmkiller commented 5 years ago

version 2 I guess, I've followed your documentation. And yes there a sendgrid function, here it is:

public function sendgrid($params) { if ($this instanceof Mailable && $this->mailDriver() == "sendgrid") { $this->withSwiftMessage(function (Swift_Message $message) use ($params) { $message->embed(new \Swift_Image(static::sgEncode($params), SendgridTransport::SMTP_API_NAME)); }); } return $this; }

s-ichikawa commented 5 years ago

I tried some pattern and got the same error. that case was written use Sichikawa\LaravelSendgridDriver\SendGrid; above class but NOT written use SendGrid; in class.

These are required both, did you write both?

<?php

namespace App\Mail;

use Sichikawa\LaravelSendgridDriver\SendGrid; // ←

class ApiSimpleMailable extends Mailable
{
    use SendGrid; // ←