RickDBCN / filament-email

Log emails in your Filament project
https://filament-email-demo.marcogermani.it/
MIT License
77 stars 23 forks source link

[Bug]: Argument #1 ($record) must be of type RickDBCN\FilamentEmail\Models\Email, App\Models\EmailLog given when overriding model class #69

Closed Jacobtims closed 1 month ago

Jacobtims commented 2 months ago

What happened?

When I override the default model class in the filament-email.php config file. I get the following error:

RickDBCN\FilamentEmail\Filament\Resources\EmailResource::RickDBCN\FilamentEmail\Filament\Resources\{closure}(): 
Argument #1 ($record) must be of type RickDBCN\FilamentEmail\Models\Email, App\Models\EmailLog given, 
called in vendor/filament/support/src/Concerns/EvaluatesClosures.php on line 35

This error occurs because of line 249 in vendor / rickdbcn / filament-email / src / Filament / Resources / EmailResource.php In requires your model in the arrow functions:

TextColumn::make('from')
  ->prefix(__('filament-email::filament-email.from').': ')
  ->suffix(fn (Email $record): string => ! empty($record->attachments) ? ' ('.trans_choice('filament-email::filament-email.attachments_number', count($record->attachments)).')' : '')
  ->label(__('filament-email::filament-email.header'))
  ->description(fn (Email $record): string => Str::limit(__('filament-email::filament-email.to').': '.$record->to, 40))
  ->searchable(),

How to reproduce the bug

  1. Install the package
  2. Publish the config file
  3. Override the default model class in the filament-email.php config file
  4. Open the Mail Logs page

Package Version

1.4.8

PHP Version

8.2.20

Laravel Version

10.48.15

Which operating systems does with happen with?

macOS, Linux

Notes

No response

marcogermani87 commented 2 months ago

Hi @Jacobtims, thanks for reporting! I'm digging into the problem to solve.

marcogermani87 commented 1 month ago

Hi @Jacobtims,

after some check i can assume this isn't an issue.

The right way to override Email model is to extend the new model with RickDBCN\FilamentEmail\Models\Email:

src/app/Models/Email.php

<?php

namespace App\Models;

use RickDBCN\FilamentEmail\Models\Email as BaseEmail;

class Email extends BaseEmail
{

}

With this method no conflicts will popped out.

After this you can override all the methods from the parent class.