jpswade/laravel-database-tools
Laravel Database Tools adds handy Artisan commands to create databases, dump/restore from SQL files or Spatie backups, update charset/collation, optimize MySQL tables, and add SQLite MySQL-compat functions for tests. Ideal for dev workflows.
The "missing" database toolset for Laravel. A set of commonly used Database Tools for Laravel.
Tested against Laravel 10-13 on PHP 8.1-8.4.
With this package you can:
Install the package into your Laravel application:
composer require --dev jpswade/laravel-database-toolsNote: It's wise to only install these tools in development by default, as it's rare you should need them in a production environment.
Publish and customise your own dbtools.php file:
php artisan vendor:publish --provider="Jpswade\LaravelDatabaseTools\ServiceProvider" --tag="config"This allows you to set the source database and/or filesystem for the backup.
dbtools.database - Define the source database for the db:dump command, similar to Laravel databases config.dbtools.filesystem - Define the source filesystem for the db:getFromBackup command, similar to Laravel filesystems
config.dbtools.filesystem.path - Define the path for the db:getFromBackup command.dbtools.import - Here you can define the method (command or normal) for the db:importFromFile command.Note:
db:getFromBackup command falls back to the spatie/laravel-backup package for configuration.The commands are:
db:create - Creates the database schema.db:dump - Fetch a copy of the latest database from the configured server.db:getFromBackup - Download database backup file from backup.db:importFromFile {file?} - Import data from a sql file into a database.db:charset - Changes the charset and collation to whatever the database is set to use.db:optimize - Optimizes your database tables.For testing you can add the provider to your Test:
protected function registerServiceProviders(): void
{
$this->app->register(SqliteMysqlCompatibilityProvider::class);
}
protected function setUp(): void
{
parent::setUp();
$this->registerServiceProviders();
}
In production, follow the usual Registering Providers instructions:
In config/app.php, find the providers array and add:
'providers' => [
// Other Service Providers
Jpswade\LaravelDatabaseTools\SqliteMysqlCompatibilityProvider::class,
],
These are limitations you'll come across if you use certain commands:
db:getFromBackup command relies on the league/flysystem-aws-s3-v3 "^1.0" package, when you use
the Amazon S3 Driver as per the Laravel docs.db:dump command depends on spatie/db-dumper.db:importFromFile command can only import .sql files.db:optimize command only works with MySQL (at the moment).The package ships an opinionated dev-tooling stack alongside the test suite:
composer pint - applies Laravel Pint formatting (Laravel preset + declare_strict_types, strict_comparison, is_null, modernize_types_casting). Config lives in pint.json.composer pint-test - the read-only equivalent used by CI; fails if anything needs reformatting.composer phpunit - test suite (Testbench + PHPUnit).composer phpstan - static analysis at Larastan level 6 with phpstan-strict-rules; pre-existing issues are captured in phpstan-baseline.neon.composer test - runs Pint (test mode), PHPStan, then PHPUnit.This package also installs Laravel Boost and jpswade/laravel-best-practices as dev dependencies for AI-assisted development. The committed boost.json opts contributors into the relevant skills for Cursor, Claude Code, and Codex; run php artisan boost:install --no-interaction after composer install to materialise those skills into your editor's agent directory. Contributors using a different editor can override locally - boost.json is the maintainer default, not a hard requirement.
CI runs the test suite across the full PHP x Laravel matrix on every push and pull request - see .github/workflows/tests.yml.
% composer require league/flysystem-aws-s3-v3:~1.0
Note: Needed for db:getFromBackup command to use the S3 Driver.
% composer require league/flysystem-aws-s3-v3
% composer require spatie/db-dumper
Note: Needed by the db:dump command.
How can I help you explore Laravel packages today?