RickDBCN / filament-email

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

[Bug]: Class name must be a valid object or a string #49

Closed patriktoth67 closed 6 months ago

patriktoth67 commented 6 months ago

What happened?

After composer update today, I get the following error:

Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi

   Error

  Class name must be a valid object or a string

  at vendor\rickdbcn\filament-email\src\FilamentEmailServiceProvider.php:35
     31▕
     32▕     public function bootingPackage()
     33▕     {
     34▕         $this->callAfterResolving(Schedule::class, function (Schedule $schedule) {
  ➜  35▕             $class = get_class(new (Config::get('filament-email.resource.model')));
     36▕             if (class_exists($class)) {
     37▕                 $schedule->command('model:prune --model="'.$class.'"')->daily();
     38▕             }
     39▕         });

  1   vendor\laravel\framework\src\Illuminate\Container\Container.php:1294
      RickDBCN\FilamentEmail\FilamentEmailServiceProvider::RickDBCN\FilamentEmail\{closure}(Object(Illuminate\Console\Scheduling\Schedule), Object(Illuminate\Foundation\Application))

  2   vendor\laravel\framework\src\Illuminate\Container\Container.php:1258
      Illuminate\Container\Container::fireCallbackArray(Object(Illuminate\Console\Scheduling\Schedule))

Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1

How to reproduce the bug

composer update

Package Version

1.2.0

PHP Version

8.2

Laravel Version

11.4.0

Which operating systems does with happen with?

Windows

Notes

No response

marcogermani87 commented 6 months ago

Hi @patriktoth67, after a second run of "composer update" you encounter the same error?

If you run "php artisan schedule:list" you have the same error?

patriktoth67 commented 6 months ago

Hello!

Yes, I just ran it twice, same error.

marcogermani87 commented 6 months ago

You can replace bootingPackage() with this new code and try again?

    public function bootingPackage()
    {
        $this->callAfterResolving(Schedule::class, function (Schedule $schedule) {
            $modelClass = Config::get('filament-email.resource.model') ?? Email::class;
            $class = get_class(new $modelClass);
            if (class_exists($class)) {
                $schedule->command('model:prune --model="'.$class.'"')->daily();
            }
        });
    }
patriktoth67 commented 6 months ago

Yes, with this as well: use RickDBCN\FilamentEmail\Models\Email; The error disappeared

patriktoth67 commented 6 months ago

Yep, everything works like a charm:) Ty for the help!

marcogermani87 commented 6 months ago

Yes, with this as well: use RickDBCN\FilamentEmail\Models\Email; The error disappeared

Yes, my bad. You need to import the namespace as well.

marcogermani87 commented 6 months ago

Yep, everything works like a charm:) Ty for the help!

I've pushed the update on the main branch. You can checkout and check if all is ok? Thanks.

patriktoth67 commented 6 months ago

Yes, should be all good :)