Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Database Laravel Package

laravel/database

Bring Laravel’s database layer to non-Laravel projects: Illuminate Database with migrations, seeders, and Artisan CLI support. Includes Eloquent ORM, query builder, schema tools, and commands like migrate, db:seed, and make:* for MySQL/Postgres/SQL Server/SQLite.

View on GitHub
Deep Wiki
Context7

Laravel database for your non laravel projects. Built on top of illuminate/database to provide migration, seeding and artisan support

Frequently asked questions about Database
Can I use Laravel Database in a Symfony or Slim project without conflicts?
Yes, Laravel Database is framework-agnostic and only requires `illuminate/database` and `illuminate/console`. It won’t interfere with Symfony’s Doctrine or Slim’s native routing. Just configure the database connection manually in `config/database.php` and avoid Laravel-specific services like the service container.
How do I install Laravel Database in an existing PHP project?
Run `composer require luracast/database` in your project root. This installs the package and its dependencies (`illuminate/database`, `illuminate/console`, and `illuminate/filesystem`). No Laravel-specific bootstrapping is required—just configure the database connection in `config/database.php` and run `php artisan migrate` via CLI.
Does Laravel Database support PostgreSQL-specific features like JSONB or custom types?
Yes, Laravel Database supports PostgreSQL’s core features, including JSONB, arrays, and custom types, through the underlying `illuminate/database` component. However, advanced PostgreSQL-specific tools (e.g., `pg_dump` integration) require manual setup or additional libraries. Test your schema migrations to ensure compatibility.
Will Eloquent models work with my existing raw SQL or PDO queries?
Eloquent models can coexist with raw SQL or PDO, but avoid mixing them in the same query layer to prevent conflicts. Use Eloquent for ActiveRecord operations (e.g., `User::create()`) and raw SQL for complex queries. The query builder (`DB::select()`) bridges both approaches seamlessly.
How do I run migrations in production without SSH access?
Laravel Database’s Artisan commands require PHP CLI. If SSH isn’t available, use a web-based alternative like Laravel Forge, Deployer scripts, or a CI/CD pipeline (e.g., GitHub Actions) to trigger migrations via a `php artisan migrate` command. Avoid web-based Artisan wrappers—they’re less secure and may hit PHP timeouts.
Can I use Laravel Database’s `make:migration` command to generate migrations for an existing database schema?
Yes, but you’ll need to manually define the schema in the migration file. Laravel Database doesn’t reverse-engineer existing tables. Use tools like `doctrine/dbal` or `laravel/scout` for schema inspection first, then adapt the output into a migration file. Alternatively, use `php artisan db:show` (if supported) to inspect the current schema.
Is Laravel Database compatible with PHP 8.1+ features like enums or attributes?
Laravel Database supports PHP 8.0+ and works with enums and attributes, but Eloquent models must use the `#[Attribute]` syntax (PHP 8.0+) or annotations (PHP 7.4+) for casting or accessors. Test your models thoroughly, as some Laravel-specific features (e.g., `HasFactory`) may require adjustments for non-Laravel projects.
How do I test Eloquent models in a non-Laravel PHPUnit setup?
Use PHPUnit’s `DatabaseTestCase` or `TestCase` with a fresh database per test. Laravel Database doesn’t include Laravel’s testing helpers (e.g., `RefreshDatabase`), so manually truncate tables or use transactions. For seeders, call them explicitly in `setUp()` or use a library like `dbunit` for data fixtures.
What’s the best way to handle database transactions in Laravel Database?
Use Eloquent’s `DB::transaction()` or the query builder’s `beginTransaction()`. For migrations, transactions are automatic during `migrate:refresh`. Avoid long-running transactions in production, as they can lock tables. Roll back manually with `DB::rollBack()` if needed.
Are there alternatives to Laravel Database for standalone Eloquent ORM?
If you only need Eloquent without migrations or Artisan, consider `illuminate/database` alone (~10MB) or `doctrine/orm` for a more traditional ORM. For migration-only needs, `php-migrate/migrate` or `cakephp/migrations` are lighter. Laravel Database is ideal if you want the full Laravel database stack (Eloquent + migrations + CLI) in a non-Laravel project.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport