PHP code example of spatie / laravel-mailable-test

1. Go to this page and download the library: Download spatie/laravel-mailable-test library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

spatie / laravel-mailable-test example snippets


return [

    /*
     * This class will be used to generate argument values for the constructor
     * of a mailable. This can be any class as long as it
     * extends \Spatie\MailableTest\ArgumentValueProvider::class
     */
    'argument_value_provider_class' => \Spatie\MailableTest\FakerArgumentValueProvider::class,

    /*
     * Base namespace Mailable classes
     */
    'base_namespace' => 'App\Mail',
];

public function __construct(string $title, Order $order) 
{
   ...
}

php artisan mail:send-test "App\Mail\OrderConfirmation" [email protected] --values="title:My title,order:5"

namespace App;

use Spatie\MailableTest\FakerArgumentValueProvider;

class MyCustomArgumentValueProvider extends FakerArgumentValueProvider
{
       protected function getModelInstance(string $mailableClass, string $argumentName, Model $model, $id): Model
       {
          return factory(get_class($model));
       }
}
bash
php artisan mail:send-test "OrderConfirmation" [email protected]
bash
php artisan vendor:publish --provider="Spatie\MailableTest\MailableTestServiceProvider" --tag="config"
bash
php artisan mail:send-test "App\Mail\MyMailable" [email protected]