[9.x] Add ability to determine if attachments exist#43967
Merged
taylorotwell merged 10 commits intolaravel:9.xfrom Sep 8, 2022
Merged
[9.x] Add ability to determine if attachments exist#43967taylorotwell merged 10 commits intolaravel:9.xfrom
taylorotwell merged 10 commits intolaravel:9.xfrom
Conversation
Member
|
Should this work with attachable objects? |
Member
|
Converting to draft and working on some improvements to support attachments / attachables and adding some tests for us as well. |
Member
$mail->attach('style', ['mime' => 'text/css']);
$mail->hasAttachment('style');
// false
$mail->hasAttachment('style', ['mime' => 'text/css']);
// trueOne 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');
// falseThis 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(...); |
Contributor
Author
|
@timacdonald thanks!! I wasn’t sure where/how to test the new methods. Here’s a PR with documentation as well: laravel/docs#8195 |
Member
|
No troubles at all. Thanks for PR'ing the feature ❤️ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: