binomeway / nova-contact-tool
A Laravel Nova tool to configure contact details and send mails based on them.
Requires
- php: >=8.0
- dacastro4/laravel-gmail: ^5.1.21
- eminiarts/nova-tabs: ^1.4
- laravel/nova: ^3.0
- optimistdigital/nova-settings: ^3.1
- spatie/laravel-package-tools: ^1.1
- whitecube/nova-flexible-content: ^0.2.4
README
A package to manage contact information such as: email, phone, socials and forms.
Installation
You can install the package via composer:
composer require binomeway/nova-contact-tool
Install nova-settings
composer require optimistdigital/nova-settings
Add the following line to the boot method within the NovaServiceProvider.php in order to be able to modify contact data withing Nova.
// NovaServiceProvider.php public function tools() { return [ \OptimistDigital\NovaSettings\NovaSettings\NovaSettings::make(), \BinomeWay\NovaContactTool\NovaContactTool\NovaContactTool::make(), ]; }
You have to publish and run the migrations
php artisan vendor:publish --provider="BinomeWay\NovaContactTool\ToolServiceProvider" --tag="nova-contact-tool-migrations" php artisan migrate
You can publish the config file with if needed.
php artisan vendor:publish --provider="BinomeWay\NovaContactTool\ToolServiceProvider" --tag="nova-contact-tool-config"
This is the contents of the published config file:
return [ 'default_to' => '', 'default_subject' => '', 'save_messages' => true, 'save_subscribers' => true, 'priority' => 3, 'delete_on_unsubscribe' => false, 'enable_gmail_api' => env('ENABLE_GMAIL_API', false), ];
Usage
Subscribers
Making a new subscriber.
use BinomeWay\NovaContactTool\Facades\Contact; $subscriber = Contact::subscribe($email, $name, $phone);
use BinomeWay\NovaContactTool\Facades\Contact; Contact::unsubscribe($subscriber);
Sending Mails
Send emails easy as that.
use BinomeWay\NovaContactTool\Facades\Contact; Contact::send($message, $subscriber);
Example
use BinomeWay\NovaContactTool\Facades\Contact; use BinomeWay\NovaContactTool\Models\Subscriber; // Perform validations // Create a subscriber $subscriber = new Subscriber(); // or use the subscribe method $subscriber = Contact::subscribe($email, $name, $phone); $message = 'Hello!'; $to = 'hello@binomeway.com'; // Optional $contact = Contact::send($message, $subscriber, $to); // Checking if the mail was sent. if($contact->hasSucceded()){ flash()->message('success', 'Yay! Email was sent.'); } if($contact->hasFailed()){ flash()->message('error', $contact->errorMessage()); }
Sending using Gmail API
First you need to enable the Gmail API features.
ENABLE_GMAIL_API=true
Further, add the credentials in the .env
file.
GOOGLE_PROJECT_ID= GOOGLE_CLIENT_ID= GOOGLE_CLIENT_SECRET= GOOGLE_REDIRECT_URI=
Or use a JSON credentials file by adding it to the path: storage/gmail/tokens/gmail-json.json
Adding more options
GOOGLE_ALLOW_MULTIPLE_CREDENTIALS=true GOOGLE_ALLOW_JSON_ENCRYPT=true
Next step is to authorize a Gmail Account by using the admin panel.
That's it. Now you can use the same send
method, and it will work.
Note: The authorization login won't work on localhost. Gmail doesn't allow local domains
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.