Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
patriktoth67 opened this issue Apr 22, 2024 · 8 comments
Closed

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

patriktoth67 opened this issue Apr 22, 2024 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@patriktoth67
Copy link

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

@patriktoth67 patriktoth67 added the bug Something isn't working label Apr 22, 2024
@marcogermani87 marcogermani87 self-assigned this Apr 22, 2024
@marcogermani87
Copy link
Collaborator

marcogermani87 commented Apr 23, 2024

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
Copy link
Author

Hello!

Yes, I just ran it twice, same error.

@marcogermani87
Copy link
Collaborator

marcogermani87 commented Apr 23, 2024

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
Copy link
Author

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

@patriktoth67
Copy link
Author

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

@marcogermani87
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Author

Yes, should be all good :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants