Skip to content

Commit

Permalink
feat: add additional configuration to the app service provider
Browse files Browse the repository at this point in the history
  • Loading branch information
bensherred committed Nov 19, 2024
1 parent e810ec5 commit 6b60877
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Modules/Default/DefaultModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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'),
);
Expand All @@ -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();
Expand All @@ -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'),
);
Expand Down
8 changes: 2 additions & 6 deletions src/Modules/Default/Tasks/InstallPulse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 6b60877

Please sign in to comment.