- Is wp-starter/database a drop-in replacement for Laravel’s Eloquent ORM and Query Builder?
- Yes, it provides a Laravel-compatible alternative with Eloquent ORM, Query Builder, and Schema Builder. The package uses Laravel’s Capsule pattern, allowing you to replace the default DB facade with minimal configuration. However, it’s not a direct Laravel core dependency—it’s a standalone library designed to work alongside Laravel.
- How do I install and configure wp-starter/database in a Laravel project?
- Run `composer require wp-starter/database`, then configure it via Capsule’s `Manager`. Define your database connection in the `config/database.php` file or dynamically via code. Use `$capsule->bootEloquent()` to enable Eloquent models, and access queries via `Capsule::table()` or `Model::query()`.
- Does this package support Laravel’s migrations system?
- Yes, it includes a Schema Builder compatible with Laravel migrations. You can define migrations using `Capsule::schema()` and run them via Artisan commands or manually. The syntax mirrors Laravel’s native migrations, so existing Laravel migration files can often be reused with minor adjustments.
- What Laravel versions does wp-starter/database support?
- The package is designed to work with Laravel 8.x and 9.x, leveraging the Capsule pattern for compatibility. It avoids hard dependencies on Laravel core, so it may also work with older versions (7.x) but isn’t officially tested for them. Check the package’s `composer.json` for exact PHP and Laravel version requirements.
- Can I use Eloquent models with this package, and how do they differ from Laravel’s default?
- Absolutely. Eloquent models work identically to Laravel’s default, with methods like `where()`, `create()`, and relationships. The only difference is the underlying query builder. You’ll need to install `wp-starter/events` for observers, but core CRUD operations and relationships (hasOne, belongsTo) function as expected.
- Will this package work in production, and are there performance concerns?
- Yes, it’s production-ready and optimized for performance. The Query Builder and Eloquent use PDO under the hood, just like Laravel’s default. However, since it’s not part of Laravel’s core, test thoroughly in staging to ensure no edge cases exist with your specific database (e.g., MySQL vs. PostgreSQL).
- Are there alternatives to wp-starter/database for Laravel projects?
- If you’re looking for a Laravel-native solution, stick with the built-in Eloquent ORM and Query Builder. For additional features, consider packages like Spatie’s `laravel-query-builder` or `spatie/laravel-activitylog`. However, if you need a standalone, framework-agnostic database layer with Eloquent compatibility, this package is a solid choice.
- How do I handle database connections for multiple environments (e.g., local, staging, production)?
- Use Laravel’s standard `.env` configuration. Define connections in `config/database.php` and reference them via Capsule’s `addConnection()` method. The package supports all Laravel environment variables, so you can switch databases seamlessly without modifying code.
- Does this package support testing with Laravel’s testing tools like Pest or PHPUnit?
- Yes, it integrates smoothly with Laravel’s testing tools. Use `Capsule::schema()->create()` in your test setup to define test databases, and mock Eloquent models like you would with Laravel’s default ORM. The package follows Laravel’s testing conventions, so existing test suites will require minimal adjustments.
- Can I use wp-starter/database alongside Laravel’s default DB facade, or do I need to choose one?
- You can use both, but it’s not recommended for the same database connection to avoid conflicts. The package is designed to replace Laravel’s DB facade via Capsule. If you need to interact with multiple database systems (e.g., MySQL and PostgreSQL), configure separate Capsule instances and use them contextually. For most projects, stick to one database layer.