Skip to content

Conversation

abdelhamiderrahmouni
Copy link
Contributor

Some of the laravel projects prefer to work with Immutable Dates.

Date::use(CarbonImmutable::class);

and using this package while keeping this approach results in the follwoing error

 php artisan imap:watch default --with=flags,headers,body
Watching mailbox [default]...
Message received: [7]

   TypeError 

  Cannot assign Carbon\CarbonImmutable to property DirectoryTree\ImapEngine\Laravel\Commands\HandleMessageReceived::$lastReceivedAt of type ?Illuminate\Support\Carbon

  at vendor/directorytree/imapengine-laravel/src/Commands/HandleMessageReceived.php:33
     29▕         );
     30▕ 
     31▕         $this->attempts = 0;
     32▕ 
  ➜  33▕         $this->lastReceivedAt = Date::now();
     34▕ 
     35▕         Event::dispatch(new MessageReceived($message));
     36▕     }
     37▕ }

      +20 vendor frames 

  21  artisan:13
      Illuminate\Foundation\Application::handleCommand()

@stevebauman stevebauman merged commit cb2dad5 into DirectoryTree:master Oct 7, 2025
@stevebauman
Copy link
Member

Thanks @abdelhamiderrahmouni! I've updated this to use CarbonInterface instead of using a union-type. Both Carbon and CarbonImmutable use this interface.

@stevebauman stevebauman changed the title Refactor lastReceivedAt type to support CarbonImmutable Replace Carbon types with CarbonInterface to support CarbonImmutable Oct 7, 2025
@stevebauman
Copy link
Member

I've just released v1.1.1 with this PR included.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants