-
Notifications
You must be signed in to change notification settings - Fork 11k
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
[9.x] Add ability to determine if attachments exist #43967
[9.x] Add ability to determine if attachments exist #43967
Conversation
Should this work with attachable objects? |
Converting to draft and working on some improvements to support attachments / attachables and adding some tests for us as well. |
$mail->attach('style', ['mime' => 'text/css']);
$mail->hasAttachment('style');
// false
$mail->hasAttachment('style', ['mime' => 'text/css']);
// true One thing to note however, is that when attaching an $mail->attach(Attachment::fromStorageDisk('s3', 'foo.png'));
$mail->hasAttachment(Attachment::fromStorage('s3', 'foo.png'));
// true
$mail->hasAttachmentFromStorageDisk('s3', 'foo.png');
// false This is because of the implementation of the attachment, where it really acts as a data attachment whether it is from storage or from data. I also added some assertions to compliment the existing assertions. $mail->assertHasAttachment(...);
$mail->assertHasAttachedData(...);
$mail->assertHasAttachmentFromStorage(...);
$mail->assertHasAttachmentFromStorageDisk(...); |
@timacdonald thanks!! I wasn’t sure where/how to test the new methods. Here’s a PR with documentation as well: laravel/docs#8195 |
No troubles at all. Thanks for PR'ing the feature ❤️ |
This adds the ability to determine if the given attachment(s) are included in the mailable, similar to the existing
$mail->hasTo()
,$mail->hasSubject()
, etc. methods.This is particularly useful in tests; example: