r4nkt / laravel-saasparilla
An opinionated collection of functionality to make Laravel SaaS creators' lives a little bit easier.
Fund package maintenance!
r4nkt
Requires
- php: ^8.0
- illuminate/support: ^8.0
- r4nkt/laravel-resource-tidier: ^0.5
- spatie/laravel-package-tools: ^1.4.3
Requires (Dev)
- brianium/paratest: ^6.2
- laravel/jetstream: ^2.3
- nunomaduro/collision: ^5.3
- orchestra/testbench: ^6.15
- phpunit/phpunit: ^9.3
- spatie/laravel-ray: ^1.9
- vimeo/psalm: ^4.4
README
An opinionated collection of functionality to make Laravel SaaS creators' lives a little bit easier.
This package was developed to scratch an itch, but it was also inspired by Freek and his blog post about removing inactive users and teams.
It should also be noted that it was build on another r4nkt package, which you may also want to use for any of your projects.
Finally, it's important to point out that this package benefitted from Spatie's Laravel package skeleton package.
Installation
You can install the package via composer:
composer require r4nkt/laravel-saasparilla
You can publish and run the migrations with:
php artisan vendor:publish --provider="R4nkt\Saasparilla\SaasparillaServiceProvider" --tag="laravel-saasparilla-migrations" php artisan migrate
You can publish the config file with:
php artisan vendor:publish --provider="R4nkt\Saasparilla\SaasparillaServiceProvider" --tag="laravel-saasparilla-config"
This is the contents of the published config file:
<?php use App\Models\User; use Illuminate\Auth\Events\Verified; use R4nkt\Saasparilla\Actions\Default\CulledUnverifiedUserNotifier; use R4nkt\Saasparilla\Actions\Default\DeleteUser; use R4nkt\Saasparilla\Actions\Default\FindUnverifiedUsers; use R4nkt\Saasparilla\Actions\Default\FindUsersReadyForDeletion; use R4nkt\Saasparilla\Actions\Default\MarkUserForDeletion; use R4nkt\Saasparilla\Actions\Default\UnmarkUserMarkedForDeletion; use R4nkt\Saasparilla\Features; use R4nkt\Saasparilla\Mail\CulledUnverifiedUserMail; return [ /** * Features (not yet complete): * - cleans up unverified users (default/jetstream) * - marking/notifying/unmarking * - deleting * - inactive users, aka unsubscribed/no-longer-on-trial users (default???/jetstream???) * - marking/notifying/unmarking * - deleting * - inactive teams, aka unsubscribed/no-longer-on-trial teams (default???/jetstream???) * - marking/notifying/unmarking * - deleting * - welcoming verified users */ 'features' => [ /** * Cleans up unverified users: * - finds users, marks them for deletion, and notifies them * - unmarks users who verify email before grace period expires * - deletes if still not verified after grace period expires */ Features::cleansUpUnverifiedUsers([ 'tidier' => 'unverified-users', 'unmark_on' => Verified::class, ]), ], 'tidiers' => [ /** * Culls unverified users and purges them after grace period expires. */ 'unverified-users' => [ 'culler' => 'unverified-users', 'unmarker' => 'user-for-deletion', 'handler' => 'purge-culled-users', ], ], 'cullers' => [ /** * Finds unverified users, marks them, and notifies them. Unmarks them * if/when they verify their email. */ 'unverified-users' => [ 'params' => [ 'finder' => 'unverified-users', 'marker' => 'user-for-deletion', 'notifier' => 'culled-unverified-user', ], ], ], 'handlers' => [ /** * Finds culled users and deletes them. */ 'purge-culled-users' => [ 'params' => [ 'finder' => 'users-ready-for-deletion', 'task' => 'delete-user', ], ], ], 'finders' => [ /** * Finds users that have not verified their email. */ 'unverified-users' => [ 'class' => FindUnverifiedUsers::class, 'params' => [ 'model' => User::class, 'threshold' => 14, ], ], /** * Finds users that are marked for deletion. */ 'users-ready-for-deletion' => [ 'class' => FindUsersReadyForDeletion::class, 'params' => [ 'model' => User::class, ], ], ], 'markers' => [ /** * Marks users for deletion, which will take place once the grace * period has expired. */ 'user-for-deletion' => [ 'class' => MarkUserForDeletion::class, 'params' => [ 'grace' => 30, ], ], ], 'notifiers' => [ /** * Notifies unverified users that their accounts will be deleted once * the grace period has expired. */ 'culled-unverified-user' => [ 'class' => CulledUnverifiedUserNotifier::class, 'params' => [ 'mailable' => CulledUnverifiedUserMail::class, 'email_attribute' => 'email', ], ], ], 'tasks' => [ /** * Deletes the given user. */ 'delete-user' => [ 'class' => DeleteUser::class, ], ], 'unmarkers' => [ /** * Unmarks a user for deletion, effectively reversing the related * marker. Unless it's marked for deletion in some other context, it * will no longer be deleted. */ 'user-for-deletion' => [ 'class' => UnmarkUserMarkedForDeletion::class, ], ], ];
Usage
To cull unverified users, execute the following Artisan command:
php artisan saasparilla:cull-unverified-users
To delete users that are ready to be deleted, execute the following Artisan command:
php artisan saasparilla:delete-users-ready-for-deletion
Verified Users
By default, Saasparilla is configured to listen to Laravel's Illuminate\Auth\Events\Verified
event. When fired, the user who has been verified will be unmarked. (By default, this will not impact users that were not previously marked for deletion.)
Deleting Jetstream Users with Teams
If your project uses Laravel Jetstream and is configured to use teams, then you will want to change your configuration so that the delete-user
task uses the R4nkt\Saasparilla\Actions\Jetstream\DeleteUser
class instead.
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.