Custom Fresh offers fine-grained control over migrations within your Laravel project, enabling you to select which tables will not be dropped when refreshing the database.
Tip
Always consider upgrading the package to the latest version, which is the most stable release.
Install the package by using Composer:
composer require ramadan/custom-fresh(Optional) publish the config file:
php artisan vendor:publish --tag=custom-fresh-configAfter installing the package, you will see a new fresh:custom command.
Note
Since v1.2.0, the package scans your migration files more accurately,
including nested folders, custom --path locations, and package
migration paths registered through Laravel.
You can exclude specific tables while refreshing the database inside your project:
php artisan fresh:custom users,fooThe same can be expressed with the --keep option (which can be combined with the positional argument):
php artisan fresh:custom --keep=users,personal_access_tokensImportant
Do not forget always to use the -h of the command to check out all supported options.
Anything containing *, ?, or […] is expanded with fnmatch against the database tables, so you can preserve whole groups at once:
php artisan fresh:custom "users,oauth_*,telescope_*"Pass --database= to target a non-default connection. The connection is also forwarded to the migrate command:
php artisan fresh:custom users --database=tenantUse --explain to preview exactly what would happen without dropping a single table:
php artisan fresh:custom users --explainIt prints the resolved connection, the tables that would be preserved, the tables that would be dropped, and the migration rows that would be re-inserted into the migrations table.
Publishing the config (see above) gives you config/custom-fresh.php:
return [
'always_keep' => ['users', 'personal_access_tokens'],
'patterns' => ['oauth_*', 'telescope_*'],
'confirm_in' => ['production', 'staging'],
];always_keep— tables that are preserved on every run, even if you don't list them on the command line.patterns— glob patterns expanded against the database on every run.confirm_in— environments where the command must ask for confirmation. Use--forceto bypass.
Three events are dispatched during a run, perfect for backups, audit logs, or Slack notifications:
Ramadan\CustomFresh\Events\RefreshingDatabase— fired before any destructive work, with the resolved preserve list and migration rows.Ramadan\CustomFresh\Events\TablesDropped— fired right after the drop step, with both the preserved and dropped tables.Ramadan\CustomFresh\Events\DatabaseRefreshed— fired after the underlyingmigratefinishes successfully.
The MIT License (MIT).

