F
Filament7mo ago
Eth

GenericEmail not found

I'm using
->form([
TextInput::make('subject')->required(),
RichEditor::make('body')->required(),
])
->action(function (array $data) {
Mail::to(auth()->user()->email)
->send(new GenericEmail(
subject: $data['subject'],
body: $data['body'],
));
->form([
TextInput::make('subject')->required(),
RichEditor::make('body')->required(),
])
->action(function (array $data) {
Mail::to(auth()->user()->email)
->send(new GenericEmail(
subject: $data['subject'],
body: $data['body'],
));
according to https://filamentphp.com/docs/3.x/actions/overview#what-is-an-action but I'm seeing an error message "Class "App\Filament\App\Resources\GenericEmail" not found", where can I find GenericEmail?
No description
8 Replies
Hussain4real
Hussain4real7mo ago
Did you have the GenericEmail class?
Eth
Eth7mo ago
…no, I don’t see the documentation mentioning it What should the class include if I may ask?
awcodes
awcodes7mo ago
this particular error is because you are not importing the class at the top of your file. use App\Resources\GenericEmail; That assumes that you actually have that class at that path. GenericEmail is something custom, so we don't know anything about where it is stored in your app or if it even exists in your app.
Samir
Samir7mo ago
This is just an example. You have to create a mailable class and replace the GenericEmail class with yours. You must go through Laravel mail documentation first and use mailable command to generate your class, write email body code and view. check this: https://laravel.com/docs/10.x/mail
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
Samir
Samir7mo ago
BTW you can also check my implementation in how I use this mailable in my filament code.
use App\Mail\BuyerInquiryEmail;
use Illuminate\Support\Facades\Mail;

Tables\Actions\Action::make('Approve')
->action(function (Inquiry $record) {
$record->status = InquiryEmailStatusEnum::APPROVED;
$record->save();
Notification::make()
->title('Inquiry Approved successfully')
->success()
->send();
// $this->dispatch('inquiry-approved', title: $record->id);

$recipeintEmail = Inquiry::find($record->id)->buyer->email;
Mail::to($recipeintEmail)->send(new BuyerInquiryEmail($record));
})
->icon('heroicon-m-check-circle')
->hidden(fn (Inquiry $record) => $record->status === InquiryEmailStatusEnum::APPROVED),
use App\Mail\BuyerInquiryEmail;
use Illuminate\Support\Facades\Mail;

Tables\Actions\Action::make('Approve')
->action(function (Inquiry $record) {
$record->status = InquiryEmailStatusEnum::APPROVED;
$record->save();
Notification::make()
->title('Inquiry Approved successfully')
->success()
->send();
// $this->dispatch('inquiry-approved', title: $record->id);

$recipeintEmail = Inquiry::find($record->id)->buyer->email;
Mail::to($recipeintEmail)->send(new BuyerInquiryEmail($record));
})
->icon('heroicon-m-check-circle')
->hidden(fn (Inquiry $record) => $record->status === InquiryEmailStatusEnum::APPROVED),
And then create a mailable class like I created in app\mail\BuyInquiryEmail.php using command
php artisan make:mail BuyInquiryEmail
php artisan make:mail BuyInquiryEmail
. I have also attached below code for generated BuyerInquiryEmail class.
Samir
Samir7mo ago
BuyerInquiryEmail mailable class
Samir
Samir7mo ago
then create view file for your email body. in mailable class path for view blade file is generated. Mine is 'emails.buyer-inquiry-email' in resource/view/emails.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Product Inquiry Email</title>
<!-- Include Tailwind CSS styles -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css">
</head>
<body class="p-8 font-sans bg-gray-100">

<div class="max-w-md p-8 mx-auto bg-white rounded shadow-md">

<h2 class="mb-4 text-2xl font-bold">Product Inquiry</h2>

<p class="mb-4">Dear {{ $sellerName }},</p>

<p class="mb-2">You have received an inquiry for your product "{{ $productName }}" from {{ $buyerName }} in {{ $buyerCountry }}.</p>

<div class="mb-4">
<strong>Details:</strong>
<ul>
<li>Quantity: {{ $quantity }} {{ $unit }}</li>
<li>Destination Port: {{ $destinationPort }}</li>
</ul>
</div>

<div class="mb-4">
<strong>Buyer's Message:</strong>
<p>{{ $buyerMsg }}</p>
</div>

<p class="mb-4">Please respond to this inquiry by clicking the button below:</p>

<a href="#" class="inline-block px-4 py-2 text-white bg-green-500 rounded">Reply to Inquiry</a>

<p class="mt-4">Thank you for using our platform!</p>

</div>

</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Product Inquiry Email</title>
<!-- Include Tailwind CSS styles -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css">
</head>
<body class="p-8 font-sans bg-gray-100">

<div class="max-w-md p-8 mx-auto bg-white rounded shadow-md">

<h2 class="mb-4 text-2xl font-bold">Product Inquiry</h2>

<p class="mb-4">Dear {{ $sellerName }},</p>

<p class="mb-2">You have received an inquiry for your product "{{ $productName }}" from {{ $buyerName }} in {{ $buyerCountry }}.</p>

<div class="mb-4">
<strong>Details:</strong>
<ul>
<li>Quantity: {{ $quantity }} {{ $unit }}</li>
<li>Destination Port: {{ $destinationPort }}</li>
</ul>
</div>

<div class="mb-4">
<strong>Buyer's Message:</strong>
<p>{{ $buyerMsg }}</p>
</div>

<p class="mb-4">Please respond to this inquiry by clicking the button below:</p>

<a href="#" class="inline-block px-4 py-2 text-white bg-green-500 rounded">Reply to Inquiry</a>

<p class="mt-4">Thank you for using our platform!</p>

</div>

</body>
</html>
Hope it helps. You can create as many mailables classes based on. how many different emails and its templates you need. Mine is one such which gets triggered when a buyer sends and inquiry email to a seller. When admin approves then email is sent to seller.
Eth
Eth7mo ago
I see, big thanks for your help Samir