utyemma/laranotice is a Laravel package.
It currently has 1 GitHub stars and 407 downloads on Packagist (latest version v1.0.2).
Install it with composer require utyemma/laranotice.
Discover more Laravel packages by utyemma
or browse all Laravel packages to compare alternatives.
Last updated
Introducing LaraNotice, your go-to package for creating dynamic notifications and email messages effortlessly. LaraNotice allows you to craft and send your notifications with ease while taking advantage of Laravel's powerful built-in notification system.
Install LaraNotice in your project
composer require utyemma/laranotice
If you intend to store your mail messages in your database, then you’ll be required to run migrations. (Note that this is the default setting)
php artisan migrate
Genrate a mailable class
php artisan make:mailable ExampleMailable
use App\Mailable\ExampleMailable;
//Send your first notification message
(new ExampleMailable)->send($user, ['mail', 'database']);
Your can learn more about Laravel's default mail message formatting from the Laravel Documentation
use Utyemma\LaraNotice\Notify;
use App\Models\User;
$users = User::all();
//Send your first notification message
Notify::subject('Your Notification Subject')
->greeting('Hello!')
->line('You have a new message.')
->line('Thank you for using our application!');
->send($users, ['mail', 'database']);
Alternatively, if your wish to send a mail instead of create a notification, you can do so by replacing the send method with the 'mail' method
use Utyemma\LaraNotice\Notify;
use App\Models\User;
$recievers = ['[email protected]', '[email protected]'];
$data = [
'name' => 'John Doe'
];
//Send your first notification message
(new Notify)->subject('Your Notification Subject', $data)
->greeting('Hello {{name}}')
->line('You have a new message.')
->line('Thank you for using our application!');
->mail($recievers);
By default, this package makes use of mustache as the default templating system to handle basic templating data. You can learn more about using mustache via the php documentation
However, you are free to use any custom template engine supported by PHP for your entire application or for a single mailable class. You can do so by registering custom template resolvers as shown below
This example sets the default resolver to make use of Laravel's blade templating engine. You can learn more about Laravel Blade here
namespace App\Mailable;
use Illuminate\Support\Facades\Blade;
use Utyemma\LaraNotice\Notification;
class ExampleMailable extends Notification {
public function setResolver($content, $placeholders){
return new Blade::render($content, $placeholders);
}
}
Here is an example using handlebars templating engine. Learn more about using Handle Bars in your Laravel Application. Handle Bars Docs
namespace App\Resolvers;
use Handlebars\Handlebars;
class HandleBarsResolver {
function __invoke($content, $placeholders){
return (new Handlebars)->render($content, $placeholders);
}
}
use App\Resolvers\HandleBarsResolver;
return [
'resolver' => HandleBarsResolver::class
];
When this class is provided it will be used in resolving the templates. You must ensure your your mail messages are formatted based on the templating engine you are using as your resolver.
LaraNotice provides a convenient command to clean up mailable classes and their associated database records.
# Delete a specific mailable class
php artisan mailable:delete --class=ExampleMailable
# Delete all mailable classes
php artisan mailable:delete --all
# Delete with preservation options
php artisan mailable:delete --class=ExampleMailable --preserve=database # Only deletes the file
php artisan mailable:delete --class=ExampleMailable --preserve=files # Only deletes from database
--all: Delete all mailable classes and their database records--class=: Specify a single mailable class to delete (e.g., ExampleMailable)--preserve=: Optional. Specify what to keep:
database: Preserves database records but deletes filesfiles: Preserves files but deletes database recordsThe command will ask for confirmation before performing any deletions to prevent accidental data loss.
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security-related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.