{"id":19324884,"url":"https://github.com/spatie/laravel-mailable-test","last_synced_at":"2025-05-15T13:08:42.846Z","repository":{"id":45925385,"uuid":"80032119","full_name":"spatie/laravel-mailable-test","owner":"spatie","description":"An artisan command to easily test mailables","archived":false,"fork":false,"pushed_at":"2025-02-21T11:33:53.000Z","size":134,"stargazers_count":151,"open_issues_count":0,"forks_count":15,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-15T03:49:56.644Z","etag":null,"topics":["artisan","debug","development","laravel","mail","php","test"],"latest_commit_sha":null,"homepage":"https://murze.be/2017/01/artisan-command-easily-test-mailables/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/spatie.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"custom":"https://spatie.be/open-source/support-us"}},"created_at":"2017-01-25T16:20:36.000Z","updated_at":"2025-04-04T04:40:54.000Z","dependencies_parsed_at":"2024-03-08T16:29:18.624Z","dependency_job_id":"ffa1df23-a8c7-44f1-9d8c-cdc453d678e2","html_url":"https://github.com/spatie/laravel-mailable-test","commit_stats":{"total_commits":115,"total_committers":27,"mean_commits":"4.2592592592592595","dds":0.4869565217391304,"last_synced_commit":"c7f895c724bf83844411c5612c72ea5f30845809"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-mailable-test","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-mailable-test/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-mailable-test/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-mailable-test/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spatie","download_url":"https://codeload.github.com/spatie/laravel-mailable-test/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254346624,"owners_count":22055808,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["artisan","debug","development","laravel","mail","php","test"],"created_at":"2024-11-10T02:07:20.067Z","updated_at":"2025-05-15T13:08:37.837Z","avatar_url":"https://github.com/spatie.png","language":"PHP","funding_links":["https://spatie.be/open-source/support-us"],"categories":[],"sub_categories":[],"readme":"# An artisan command to easily test a mailable\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/laravel-mailable-test.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-mailable-test)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)\n[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/spatie/laravel-mailable-test/run-tests.yml?branch=main\u0026label=tests)](https://github.com/spatie/laravel-mailable-test/actions/workflows/run-tests.yml)\n![Check \u0026 fix styling](https://github.com/spatie/laravel-mailable-test/workflows/Check%20\u0026%20fix%20styling/badge.svg)\n[![Total Downloads](https://img.shields.io/packagist/dt/spatie/laravel-mailable-test.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-mailable-test)\n\nDo you have to fill out an entire form just to test a mail sent by your app? Or even worse, complete an entire checkout process to just view and debug an order confirmation mail? Stop. The. Madness.\n\nThis package provides an artisan command that can send a mailable to an email-address. It can be used like this:\n\n```bash\nphp artisan mail:send-test \"OrderConfirmation\" recipient@mail.com\n```\n\nThe given mailable will be sent to the given recipient. Any parameters handed to the `__construct` method of the mailable class will be automatically passed in.\n\n## Support us\n\n[\u003cimg src=\"https://github-ads.s3.eu-central-1.amazonaws.com/laravel-mailable-test.jpg?t=1\" width=\"419px\" /\u003e](https://spatie.be/github-ad-click/laravel-mailable-test)\n\nWe invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).\n\nWe highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).\n\n## Installation\n\nYou can install the package via composer:\n\n``` bash\ncomposer require spatie/laravel-mailable-test\n```\n\nThe package will automatically register itself.\n\nOptionally you can publish the config-file with:\n\n```bash\nphp artisan vendor:publish --provider=\"Spatie\\MailableTest\\MailableTestServiceProvider\" --tag=\"config\"\n```\n\nThis is the contents of the published config file:\n\n```php\nreturn [\n\n    /*\n     * This class will be used to generate argument values for the constructor\n     * of a mailable. This can be any class as long as it\n     * extends \\Spatie\\MailableTest\\ArgumentValueProvider::class\n     */\n    'argument_value_provider_class' =\u003e \\Spatie\\MailableTest\\FakerArgumentValueProvider::class,\n\n    /*\n     * Base namespace Mailable classes\n     */\n    'base_namespace' =\u003e 'App\\Mail',\n];\n```\n\n## Usage\n\nTo send any mailable issue this artisan command:\n\n```bash\nphp artisan mail:send-test \"App\\Mail\\MyMailable\" recipient@mail.com\n```\n\nThis will send the given mailable to the given mail-address. The to-, cc- and bcc-address that may be set in the given mailable will be cleared. The mail will only be sent to the mail-address given in the artisan command.\n\nThe package will provide a value for any typehinted argument of the constructor of the mailable. If a argument is a `int`, `string` or `bool` the package will generated a value using [Faker](https://github.com/FakerPHP/Faker). Any argument that typehints an Eloquent model will receive the first record of that model. For all arguments that have a class typehint an argument will be generated using the container.\n\n## Customizing the values passed to the mailable constructor\n\n### Via the command\n\nThe easiest way to customize the values passed to the mailable constructor is to use the `values` option of the `mail:send-test` command.  Image the constructor for your mailable looks like this:\n\n```php\npublic function __construct(string $title, Order $order) \n{\n   ...\n}\n```\n\nThe `Order` class in this example is an eloquent model. If you don't want the package to generate fake values or use the first `Order`, you can pass a `values` option to the command. The option should get a string with comma separated pair. The first value of each pair (separated by ':') should be the name of the argument in the mailable constructor. The second value should be the value that should be passed to that argument. For arguments concerning Eloquent models, the passed value will be used as the id.\n\nSo in this example `My title` will be passed to `$title` and an `Order` with id 5 will be passed to `$order`.\n\n```php\nphp artisan mail:send-test \"App\\Mail\\OrderConfirmation\" recipient@mail.com --values=\"title:My title,order:5\"\n```\n\n### By overriding the `ArgumentValueProvider`\n\nThe class that is responsible for getting values that should be passed on to the mailable constructor is `Spatie\\MailableTest\\FakerArgumentValueProvider`. You can override this class by specifying your own class in the `argument_value_provider_class` in the `laravel-mailable-test` config file.\n\nBy default the package will pass the first record of an Eloquent model to each argument that typehints a model. If you want to use your factories instead, you can do this.\n \n```php\nnamespace App;\n\nuse Spatie\\MailableTest\\FakerArgumentValueProvider;\n\nclass MyCustomArgumentValueProvider extends FakerArgumentValueProvider\n{\n       protected function getModelInstance(string $mailableClass, string $argumentName, Model $model, $id): Model\n       {\n          return factory(get_class($model));\n       }\n}\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.\n\n## Testing\n\n``` bash\n$ composer test\n```\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.\n\n## Security\n\nIf you've found a bug regarding security please mail [security@spatie.be](mailto:security@spatie.be) instead of using the issue tracker.\n\n## Postcardware\n\nYou're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.\n\nOur address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.\n\nWe publish all received postcards [on our company website](https://spatie.be/en/opensource/postcards).\n\n## Credits\n\n- [Freek Van der Herten](https://github.com/freekmurze)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Flaravel-mailable-test","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspatie%2Flaravel-mailable-test","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Flaravel-mailable-test/lists"}