1. Go to this page and download the library: Download hmones/laravel-digest 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/ */
hmones / laravel-digest example snippets
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class UserCreatedMailable extends Mailable
{
use Queueable, SerializesModels;
public $data;
public function __construct(array $data)
{
$this->data = $data;
}
public function build(): Mailable
{
return $this->view('userCreated')->subject('10 new users are registered')->to('[email protected]');
}
}
namespace App\Observers;
use App\Mail\UserCreatedMailable;
use App\Models\User;
use Hmones\LaravelDigest\Facades\Digest;
class UserObserver
{
public function created(User $user)
{
$batchId = 'userCreated';
$mailable = UserCreatedMailable::class;
//Data can also be set to null if you don't want to attach any data to the email
$data = ['name' => $user->name];
//Frequency can take values such as daily, weekly, monthly, custom or an integer threshold 10, 20 ...etc
$frequency = 10;
Digest::add($batchId, $mailable, $data, $frequency);
}
}
html
<html>
<head><title>Sample Email</title></head>
<body>
<h1>The following users have just registered:</h1>
<ol>
@foreach($data as $record)
<li>{{$record['name']}}</li>
@endforeach
</ol>
</body>
</html>
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.