Error when Send email using Queue

I send email when have 2 event, created and updated, i test it without queue and it's working, but when iplements ShouldQueue this not work for me, i have my code like this:
<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

use App\Models\Company\EntrustRegistration;

class EntrustRegistrationNotification extends Mailable implements ShouldQueue
{
use Queueable, SerializesModels;

public EntrustRegistration $registration;
public string $action;

/**
* Create a new message instance.
*/
public function __construct(EntrustRegistration $registration, string $action)
{
$this->registration = $registration;
$this->action = $action;
}

public function build()
{
return $this->view('emails.entrust_registration_notification')
->with([
'registration' => $this->registration,
'action' => $this->action,
])
->subject("Se ha {$this->action} una encomienda");
}

}
<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

use App\Models\Company\EntrustRegistration;

class EntrustRegistrationNotification extends Mailable implements ShouldQueue
{
use Queueable, SerializesModels;

public EntrustRegistration $registration;
public string $action;

/**
* Create a new message instance.
*/
public function __construct(EntrustRegistration $registration, string $action)
{
$this->registration = $registration;
$this->action = $action;
}

public function build()
{
return $this->view('emails.entrust_registration_notification')
->with([
'registration' => $this->registration,
'action' => $this->action,
])
->subject("Se ha {$this->action} una encomienda");
}

}
5 Replies
TranceCode
TranceCodeOP7mo ago
And this is my model
<?php

namespace App\Models\Company;

use App\Mail\EntrustRegistrationNotification;
use App\Models\Company;
use Filament\Models\Contracts\HasTenants;
use Filament\Panel;
use Illuminate\Contracts\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Mail;

class EntrustRegistration extends Model implements HasTenants
{
use HasFactory;

protected $fillable = [
'nombreca',
'tipoencomienda',
'fecha',
'coowner_id',
'company_id',
];

protected static function booted(): void
{
// Event for Send Emails
self::created(function ($registration) {
Mail::to($registration->coowners->guest->email)->queue(new EntrustRegistrationNotification($registration, 'recibido'));
});
self::updated(function ($registration) {
Mail::to($registration->coowners->guest->email)->queue(new EntrustRegistrationNotification($registration, 'actualizado'));
});
}

public function companies(): BelongsTo
{
return $this->belongsTo(Company::class, 'company_id');
}

public function getTenants(Panel $panel): array|Collection
{
return $this->companies;
}

public function canAccessTenant(Model $tenant): bool
{
return $this->companies->contains($tenant);
}

public function coowners(): BelongsTo
{
return $this->belongsTo(Coowner::class, 'coowner_id');
}
}
<?php

namespace App\Models\Company;

use App\Mail\EntrustRegistrationNotification;
use App\Models\Company;
use Filament\Models\Contracts\HasTenants;
use Filament\Panel;
use Illuminate\Contracts\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Mail;

class EntrustRegistration extends Model implements HasTenants
{
use HasFactory;

protected $fillable = [
'nombreca',
'tipoencomienda',
'fecha',
'coowner_id',
'company_id',
];

protected static function booted(): void
{
// Event for Send Emails
self::created(function ($registration) {
Mail::to($registration->coowners->guest->email)->queue(new EntrustRegistrationNotification($registration, 'recibido'));
});
self::updated(function ($registration) {
Mail::to($registration->coowners->guest->email)->queue(new EntrustRegistrationNotification($registration, 'actualizado'));
});
}

public function companies(): BelongsTo
{
return $this->belongsTo(Company::class, 'company_id');
}

public function getTenants(Panel $panel): array|Collection
{
return $this->companies;
}

public function canAccessTenant(Model $tenant): bool
{
return $this->companies->contains($tenant);
}

public function coowners(): BelongsTo
{
return $this->belongsTo(Coowner::class, 'coowner_id');
}
}
TranceCode
TranceCodeOP7mo ago
i update too the
QUEUE_CONNECTION=database
QUEUE_CONNECTION=database
in .env
No description
Dennis Koch
Dennis Koch7mo ago
And what’s the error? Does it work without queuing?
BKF Dev
BKF Dev7mo ago
Check the error on horizon, what it says ?
TranceCode
TranceCodeOP6mo ago
i fix the problem guys, thank you so much, i modify my code and it's working
Want results from more Discord servers?
Add your server