Created
June 21, 2021 20:01
-
-
Save alistaircol/5716274c9c1ef76a3fb74284af83f46e to your computer and use it in GitHub Desktop.
CommandListenerProvider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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