Level 104
The base Mailable class you extend does not define a type for $subject; so you cannot.
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have the following PHP
<?php
namespace App\Mail;
use App\Models\Warranty;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class WarrantyNotification extends Mailable implements ShouldQueue
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*/
public function __construct(
public Warranty $warranty,
public string $subject,
public string $content,
) {
}
/**
* Get the message envelope.
*/
public function envelope(): Envelope
{
return new Envelope(
subject: $this->subject,
);
}
/**
* Get the message content definition.
*/
public function content(): Content
{
return new Content(
view: 'emails.warranties.template',
with: [
'template' => $this->content,
'data' => [
'name' => $this->warranty->name,
'mobile' => $this->warranty->mobile,
'email' => $this->warranty->email,
'address' => $this->warranty->address,
'reference_number' => $this->warranty->reference_number,
'product_name' => $this->warranty->product_name,
'invoice_number' => $this->warranty->invoice_number,
'store_name' => $this->warranty->store_name,
'invoice_date' => $this->warranty->invoice_date,
],
]
);
}
/**
* Get the attachments for the message.
*
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
*/
public function attachments(): array
{
return [
//
];
}
}
In this code, the issue is when I define
public string $subject
It's not working
Type of App\Mail\WarrantyNotification::$subject must not be defined
If I renamed the subject into any other name then it worked fine.
The base Mailable class you extend does not define a type for $subject; so you cannot.
Please or to participate in this conversation.