{"id":18879727,"url":"https://github.com/loilo/contao-illuminate-database-bundle","last_synced_at":"2025-10-24T13:26:04.435Z","repository":{"id":62518777,"uuid":"199159613","full_name":"loilo/contao-illuminate-database-bundle","owner":"loilo","description":"💾 Use Laravel's Illuminate Database abstraction in Contao","archived":false,"fork":false,"pushed_at":"2020-12-23T23:04:27.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-31T03:12:37.953Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/loilo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-27T12:03:42.000Z","updated_at":"2020-12-23T23:04:29.000Z","dependencies_parsed_at":"2022-11-02T13:46:08.527Z","dependency_job_id":null,"html_url":"https://github.com/loilo/contao-illuminate-database-bundle","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loilo%2Fcontao-illuminate-database-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loilo%2Fcontao-illuminate-database-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loilo%2Fcontao-illuminate-database-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loilo%2Fcontao-illuminate-database-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/loilo","download_url":"https://codeload.github.com/loilo/contao-illuminate-database-bundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239841742,"owners_count":19705981,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T06:39:04.689Z","updated_at":"2025-10-24T13:26:04.363Z","avatar_url":"https://github.com/loilo.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Illuminate Database for Contao\n[![Tests](https://badgen.net/github/checks/loilo/contao-illuminate-database-bundle/master)](https://github.com/loilo/contao-illuminate-database-bundle/actions)\n[![Version on packagist.org](https://badgen.net/packagist/v/loilo/contao-illuminate-database-bundle)](https://packagist.org/packages/loilo/contao-illuminate-database-bundle)\n\nUse Laravel's [Illuminate Database](https://laravel.com/docs/queries) abstraction in Contao with support for Contao models.\n\n## Installation\n```bash\ncomposer require loilo/contao-illuminate-database-bundle\n```\n\n## Usage\n### Getting Started\nGet the `db()` helper function:\n\n```php\nuse function Loilo\\ContaoIlluminateDatabaseBundle\\Database\\db;\n```\n\nCalling the `db()` function creates a new [Laravel query builder](https://laravel.com/docs/queries) instance.\n\n### Basic Queries\nThis is how we'd fetch ID and name of the earliest admin of the Contao installation:\n\n```php\n$row = db()\n  -\u003eselect('id', 'name')\n  -\u003efrom('user')\n  -\u003ewhere('admin', '1')\n  -\u003eorderBy('dateAdded')\n  -\u003efirst();\n```\n\n\u003e Note how the `tl_` prefix is automatically prepended to table names, so we actually read from `tl_user`.\n\nThe above is just a very basic example. To get an idea of what's possible with this API, consult the [Laravel docs](https://laravel.com/docs/queries).\n\n### Fetching Models\nIn addition to Laravel's built-in methods, the query builder of this package exposes an additional `asModel()` method.\n\nUsing it inside a query builder chain will instruct the `get()`, `first()`, `find()` and `cursor()` methods to return Contao models instead of plain database records.\n\nTo explain this based on the example above:\n\n```php\n$user = db()\n  -\u003efrom('user')\n  -\u003easModel() // \u003c- notice this line\n  -\u003ewhere('admin', '1')\n  -\u003eorderBy('dateAdded')\n  -\u003efirst();\n\n// $user will be an instance of \\UserModel\n```\n\n### Customizing Connections\nThe `db()` function takes an optional argument which may override keys from the default connection configuration [passed to Laravel's connection manager](https://laravel.com/api/5.8/Illuminate/Database/Capsule/Manager.html#method_addConnection):\n\n```php\n// Set an empty prefix to use the \"tl_user\" table\ndb([ 'prefix' =\u003e '' ])-\u003efrom('tl_user')-\u003efirst();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floilo%2Fcontao-illuminate-database-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Floilo%2Fcontao-illuminate-database-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floilo%2Fcontao-illuminate-database-bundle/lists"}