mydnic / laravel-subscribers
Easily Manage Internal Newsletter Subscribers in Laravel
Installs: 4 401
Dependents: 0
Suggesters: 0
Security: 0
Stars: 26
Watchers: 2
Forks: 5
Open Issues: 0
Requires
- php: ^7.1|8.*
- laravel/framework: >=8.40.0
Requires (Dev)
- mockery/mockery: ^1.3
- orchestra/testbench: ^6.17.0
- phpunit/phpunit: ^9.5
README
Installation
You may use Composer to Install Laravel Subscribers:
composer require mydnic/laravel-subscribers
The package will automatically register itself
You then must publish the migration with:
php artisan vendor:publish --provider="Mydnic\Subscribers\SubscribersServiceProvider" --tag="subscribers-migrations"
Usage
In your view, you simply need to add a form that you can customize the way you want
<form action="{{ route('subscribers.store') }}" method="post"> @csrf <input type="email" name="email"> <input type="submit" value="submit"> </form> @if (session('subscribed')) <div class="alert alert-success"> {{ session('subscribed') }} </div> @endif
Delete
Simply provide this link to your subscribers:
<a href="{{ route('subscribers.delete', ['email' => $subscriber->email]) }}">unsubscribe</a>
This will generate a link like /subscribers/delete?email=email@example.com
Subscribe manually from the user model
Alternatively, you can manage the subscription of a user from the user model.
In order to do that you will need to add the CanSubscribe
trait
use Mydnic\Subscribers\Traits\CanSubscribe; class User extends Model { use CanSubscribe; }
// subscribe user $user->subscribe(); // unsubscribe user $user->unsubscribe();