Skip to content

Instantly share code, notes, and snippets.

@alistaircol
Created June 21, 2021 20:01
Show Gist options
  • Save alistaircol/5716274c9c1ef76a3fb74284af83f46e to your computer and use it in GitHub Desktop.
Save alistaircol/5716274c9c1ef76a3fb74284af83f46e to your computer and use it in GitHub Desktop.
CommandListenerProvider
<?php
namespace App\Providers;
use Event;
use Illuminate\Console\Events\CommandStarting;
use Illuminate\Database\Events\MigrationsEnded;
use Illuminate\Support\ServiceProvider;
class CommandListenerProvider extends ServiceProvider
{
public $isPretend = true;
/**
* Register services.
*
* @return void
*/
public function register()
{
//
}
public function boot()
{
Event::listen(MigrationsEnded::class, function (MigrationsEnded $event) {
if ($this->isPretend) {
return;
}
// TODO: whatever you want post-migration :)
});
Event::listen(CommandStarting::class, function (CommandStarting $event) {
if ($event->input->hasParameterOption('migrate')
&& !$event->input->hasParameterOption('--pretend')
) {
$this->isPretend = false;
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment