Monday, June 24, 2024
HomePHPStop Harmful Instructions From Working in Laravel

Stop Harmful Instructions From Working in Laravel


As of Laravel 11.9 now you can stop instructions like database migrations from by chance operating in manufacturing environments with a Prohibitable trait:

use IlluminateConsoleCommand;

use IlluminateConsoleProhibitable;

 

class SomeDestructiveCommand extends Command

{

use Prohibitable;

}

 

// SomeDestructiveCommand::prohibit($this->app->isProduction());

The Laravel framework contains some database instructions that embody the Prohibitable trait, reminiscent of db:wipe, migrate:contemporary, migrate:refresh, and migrate:reset:

public operate boot(): void

{

FreshCommand::prohibit();

RefreshCommand::prohibit();

ResetCommand::prohibit();

WipeCommand::prohibit();

}

Utilizing the DB Facade, you’ll be able to prohibit harmful database instructions constructed into Laravel:

// Prohibits: db:wipe, migrate:contemporary, migrate:refresh, and migrate:reset

DB::prohibitDestructiveCommands($this->app->isProduction());

The prohibit() methodology accepts a Boolean argument that defaults to true, and you’ll conditionally stop instructions from operating utilizing no matter logic you want, as a way to nonetheless run them in growth environments:

public operate boot(): void

{

YourCommand::prohibit($this->app->isProduction());

}



RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments