I'm proud to announce that our team has released a new package called https://github.com/spatie/laravel-model-flags. This one makes it easy to add flags to any model in your app.
namespace App\Console\Commands; use App\Models\User; use App\Mails\ExtraMail; use Illuminate\Console\Command; use Illuminate\Support\Facades\Mail; class SendExtraMailCommand extends Command { protected $signature = 'send-extra-mail'; protected $description = 'Send extra mail to all users'; public function handle() { $this->info('Sending extra mail to all users...'); User::each(function(User $user) { $this->comment("Sending mail to {$user->email}"); Mail::to($user->email)->queue(new ExtraMail()); }); $this->info('All done!'); }}
I've coded flag-like functionality in multiple projects before, and I'm glad I finally took the time to extract it to package.
This isn't the first time our team has extracted common functionality from a project to a reusable package.