laravel-doctrine-query maintained by ncphillips
Laravel Doctrine Query
Ergonomic querying traits for Doctrine entities in Laravel.
This package gives Doctrine entities an Eloquent-flavoured static query API so you can write
User::find(1) instead of reaching for the EntityManager and a repository at every call site.
Installation
composer require ncphillips/laravel-doctrine-query
The service provider is registered automatically via Laravel package discovery.
Usage
Add the Queryable trait to a Doctrine entity:
use Doctrine\ORM\Mapping as ORM;
use Ncphillips\LaravelDoctrineQuery\Queryable;
#[ORM\Entity]
class User
{
use Queryable;
// ...
}
You can then query it statically:
User::all(); // array<User>
User::find($id); // ?User
User::findBy(['admin' => true]); // array<User>
User::findOneBy(['name' => 'Ada']); // ?User
User::count(['admin' => true]); // int
User::query() // Doctrine\ORM\QueryBuilder, aliased "user"
->where('user.admin = :admin')
->setParameter('admin', true)
->getQuery()
->getResult();
The EntityManager is resolved from the Laravel container on demand, so entities stay free of any constructor wiring.
Development
composer install
composer test # Pest + Orchestra Testbench, integration tests against SQLite
composer lint # Laravel Pint
Release
This project uses Conventional Commits and git-cliff to manage releases.
# Bump version, tag, and generate changelog
git cliff --bump --tag # bumps version based on commits since last tag
# Or specify the version explicitly
git cliff --bump --tag --unreleased --prepend CHANGELOG.md
# Generate changelog from scratch (first release)
git cliff --prepend CHANGELOG.md
The workflow:
- Merge feature/fix branches with conventional commit messages
- Run
git cliff --bumpto determine the next version from commit history - Review and commit the updated
CHANGELOG.mdand version bump - Tag the release (git-cliff creates the tag with
--tag) - Push tags:
git push --tags
License
MIT