diff --git a/src/Modules/Default/DefaultModule.php b/src/Modules/Default/DefaultModule.php index ba9b632..c34e2a2 100644 --- a/src/Modules/Default/DefaultModule.php +++ b/src/Modules/Default/DefaultModule.php @@ -31,7 +31,7 @@ public static function tasks(): array Tasks\RemoveDefaultController::class, Tasks\RemoveMigrationComments::class, Tasks\RemoveDownMigrations::class, - Tasks\ConfigureEloquentModels::class, + Tasks\ConfigureAppServiceProvider::class, Tasks\RemoveFillableAttributes::class, Tasks\AddIsAdminColumn::class, Tasks\ImplementMustVerifyEmail::class, diff --git a/src/Modules/Default/Tasks/ConfigureEloquentModels.php b/src/Modules/Default/Tasks/ConfigureAppServiceProvider.php similarity index 65% rename from src/Modules/Default/Tasks/ConfigureEloquentModels.php rename to src/Modules/Default/Tasks/ConfigureAppServiceProvider.php index 2412b48..6420fa9 100644 --- a/src/Modules/Default/Tasks/ConfigureEloquentModels.php +++ b/src/Modules/Default/Tasks/ConfigureAppServiceProvider.php @@ -8,7 +8,7 @@ use RedExplosion\Fabricate\Data\InstallData; use RedExplosion\Fabricate\Task; -class ConfigureEloquentModels extends Task +class ConfigureAppServiceProvider extends Task { public function __construct( protected readonly ReplaceInFileAction $replaceInFile, @@ -30,8 +30,10 @@ public function perform(InstallData $data): void use App\Models\User; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\Relation; + use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; use Illuminate\Support\ServiceProvider; + use Illuminate\Validation\Rules\Password; EOT, base_path('app/Providers/AppServiceProvider.php'), ); @@ -45,6 +47,21 @@ public function boot(): void EOT, <<<'EOT' public function boot(): void + { + $this->configureCommands(); + $this->configureModels(); + $this->configureRelations(); + $this->configurePasswordDefaults(); + } + + protected function configureCommands(): void + { + DB::prohibitDestructiveCommands( + $this->app->isProduction(), + ); + } + + protected function configureModels(): void { Model::unguard(); @@ -59,11 +76,24 @@ public function boot(): void Log::warning("Attempted to lazy load [{$relation}] on model [{$class}]."); }); } + } + protected function configureRelations(): void + { Relation::enforceMorphMap([ 'user' => User::class, ]); } + + protected function configurePasswordDefaults(): void + { + Password::defaults( + Password::min(8) + ->letters() + ->numbers() + ->symbols(), + ); + } EOT, base_path('app/Providers/AppServiceProvider.php'), ); diff --git a/src/Modules/Default/Tasks/InstallPulse.php b/src/Modules/Default/Tasks/InstallPulse.php index 56b03e3..fb4ceed 100644 --- a/src/Modules/Default/Tasks/InstallPulse.php +++ b/src/Modules/Default/Tasks/InstallPulse.php @@ -46,14 +46,10 @@ public function perform(InstallData $data): void $this->replaceInFile->handle( <<<'EOT' - Relation::enforceMorphMap([ - 'user' => User::class, - ]); + $this->configurePasswordDefaults(); EOT, <<<'EOT' - Relation::enforceMorphMap([ - 'user' => User::class, - ]); + $this->configurePasswordDefaults(); Gate::define('viewPulse', fn (User $user) => $user->is_admin); EOT,