{"id":18370007,"url":"https://github.com/statamic/eloquent-driver","last_synced_at":"2026-04-03T00:32:03.082Z","repository":{"id":38241854,"uuid":"299692524","full_name":"statamic/eloquent-driver","owner":"statamic","description":"Provides support for storing your Statamic data in a database, rather than flat files.","archived":false,"fork":false,"pushed_at":"2026-02-04T14:56:52.000Z","size":627,"stargazers_count":125,"open_issues_count":14,"forks_count":96,"subscribers_count":8,"default_branch":"5.x","last_synced_at":"2026-02-04T17:38:40.924Z","etag":null,"topics":["cms","database","eloquent","laravel","statamic"],"latest_commit_sha":null,"homepage":"https://statamic.dev/tips/storing-content-in-a-database","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/statamic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2020-09-29T17:39:46.000Z","updated_at":"2026-02-04T14:56:10.000Z","dependencies_parsed_at":"2023-10-25T19:35:46.474Z","dependency_job_id":"945ebf5e-8406-4dda-89d4-904ee6c7b8db","html_url":"https://github.com/statamic/eloquent-driver","commit_stats":{"total_commits":51,"total_committers":14,"mean_commits":3.642857142857143,"dds":0.6274509803921569,"last_synced_commit":"83d461614d1967036e0d0ec1dd069e3ce3d82e42"},"previous_names":[],"tags_count":117,"template":false,"template_full_name":null,"purl":"pkg:github/statamic/eloquent-driver","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statamic%2Feloquent-driver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statamic%2Feloquent-driver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statamic%2Feloquent-driver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statamic%2Feloquent-driver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/statamic","download_url":"https://codeload.github.com/statamic/eloquent-driver/tar.gz/refs/heads/5.x","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statamic%2Feloquent-driver/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29385953,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-12T22:07:52.078Z","status":"ssl_error","status_checked_at":"2026-02-12T22:07:49.026Z","response_time":55,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["cms","database","eloquent","laravel","statamic"],"created_at":"2024-11-05T23:35:06.413Z","updated_at":"2026-02-12T23:17:41.714Z","avatar_url":"https://github.com/statamic.png","language":"PHP","readme":"\u003c!-- statamic:hide --\u003e\n# Eloquent Driver\n\n\u003e Provides support for storing your Statamic data in a database, rather than flat files.\n\n\u003c!-- /statamic:hide --\u003e\n\n## Installation \u0026 Usage\n\nYou can install and configure the Eloquent Driver using a single command:\n\n```\nphp please install:eloquent-driver\n```\n\nThe command will install the `statamic/eloquent-driver` package, publish the config file, then prompt you to select which repositories you wish to move to the database. The command will then publish the relevant migrations and run `php artisan migrate` behind the scenes.\n\nThe command will also give you the opportunity to indicate whether you'd like existing data to be imported.\n\n### Importing flat-file content\n\nIf you originally opt-out of importing existing content, then later change your mind, you can import existing content by running the relevant commands:\n\n- Addon Settings: `php please eloquent:import-addon-settings`\n- Assets: `php please eloquent:import-assets`\n- Blueprints and Fieldsets: `php please eloquent:import-blueprints`\n- Collections: `php please eloquent:import-collections`\n- Entries: `php please eloquent:import-entries`\n- Forms: `php please eloquent:import-forms`\n- Globals: `php please eloquent:import-globals`\n- Navs: `php please eloquent:import-navs`\n- Revisions: `php please eloquent:import-revisions`\n- Taxonomies: `php please eloquent:import-taxonomies`\n- Sites: `php please eloquent:import-sites`\n\n### Assets\n\n#### Syncing\n\nIf your assets are being driven by the Eloquent Driver and you're managing your assets outside of Statamic (eg. directly in the filesystem), you should run the `php please eloquent:sync-assets` command to add any missing files to the database, and remove files that no longer exist on the filesystem.\n\n### Exporting to flat files\n\nIf you wish to move back to flat-files, you may use the following commands to export your content out of the database:\n\n- Addon Settings: `php please eloquent:export-addon-settings`\n- Assets: `php please eloquent:export-assets`\n- Blueprints and Fieldsets: `php please eloquent:export-blueprints`\n- Collections: `php please eloquent:export-collections`\n- Entries: `php please eloquent:export-entries`\n- Forms: `php please eloquent:export-forms`\n- Globals: `php please eloquent:export-globals`\n- Navs: `php please eloquent:export-navs`\n- Revisions: `php please eloquent:export-revisions`\n- Taxonomies: `php please eloquent:export-taxonomies`\n- Sites: `php please eloquent:export-sites`\n\n## Configuration\n\nThe configuration file, found in `config/statamic/eloquent-driver.php` is automatically published when you install the Eloquent Driver. \n\nFor each of the repositories, it allows you to determine if they should be driven by flat-files (`file`) or Eloquent (`eloquent`). Some repositories also have additional options, like the ability to override the model used.\n\n### Using dedicated columns for data\n\n\u003e Note: This feature is currently only available for Entries.\n\nBy default, the Eloquent Driver stores all data in a single `data` column. However, it is possible to store fields in their own columns. \n\n1. First, you'll need to enable the `map_data_to_columns` option in the `entries` section of the configuration file:\n\n    ```php\n    // config/statamic/eloquent-driver.php\n    \n    'entries' =\u003e [\n        'driver' =\u003e 'file',\n        'model' =\u003e \\Statamic\\Eloquent\\Entries\\EntryModel::class,\n        'entry' =\u003e \\Statamic\\Eloquent\\Entries\\Entry::class,\n        'map_data_to_columns' =\u003e false,\n    ],\n    ```\n\n2. Create a new migration to add the columns to the `entries` table:\n    ```bash\n    php artisan make:migration add_columns_to_entries_table\n    ```\n    \n    ```php\n    public function up()\n    {\n        Schema::create('entries', function (Blueprint $table) {\n            $table-\u003estring('description')-\u003enullable();\n            $table-\u003ejson('featured_images')-\u003enullable();\n        });\n    }\n    ```\n    \n    You should ensure that the column names match the field handles in your blueprints. You should also ensure the column type matches that of the fieldtype. As a general rule of thumb, here are some common mappings:\n\n   * Text fields should be stored as `string` columns.\n   * Relationship fields should be stored as `json` columns. (Unless `max_items` is set to `1`, in which case it should be stored as a `string` column.)\n   * Number fields should be stored as `integer` or `decimal` columns.\n\n3. Run the migration:\n    ```bash\n    php artisan migrate\n    ```\n\n4. If you're adding a column that [requires an Eloquent cast](https://laravel.com/docs/master/eloquent-mutators#attribute-casting) (eg. a `json` or `integer` column), you will need to provide your own `Entry` model in order to set the appropriate casts. You can do this by creating a new model which extends the default `Entry` model:\n\n    ```php\n    \u003c?php\n    \n    namespace App\\Models;\n    \n    class Entry extends \\Statamic\\Eloquent\\Entries\\EntryModel\n    {\n        protected function casts(): array\n        {\n            return [\n                // The casts from Statamic's base model...\n                'date'      =\u003e 'datetime',\n                'data'      =\u003e 'json',\n                'published' =\u003e 'boolean',\n        \n                // Your custom casts...\n                'featured_images' =\u003e 'json',\n            ];\n        }\n    }\n    ```\n    \n    If you're using UUIDs as your entry IDs (which is the default if you imported existing entries into the database), you should extend the `Statamic\\Eloquent\\Entries\\UuidEntryModel` class instead:\n    \n    ```php\n    class Entry extends \\Statamic\\Eloquent\\Entries\\UuidEntryModel\n    ```\n   \n    Once created, you will need to update the model in the `entries` section of the configuration file:\n\n    ```diff\n    - 'model' =\u003e \\Statamic\\Eloquent\\Entries\\EntryModel::class,\n    + 'model' =\u003e \\App\\Models\\Entry::class,\n    ```\n\n5. If you have existing entries, you will need to re-save them to populate the new columns. You can do this by pasting the following snippet into `php artisan tinker`:\n    ```php\n    \\Statamic\\Facades\\Entry::all()-\u003eeach-\u003esave();\n    ```\n\n6. And that's it! Statamic will now read and write data to the new columns in the `entries` table, rather than the `data` column.\n\n### Selecting specific blueprint types for Eloquent\n\nBy default, setting the driver for blueprints to `eloquent` will apply to *all* blueprints. However, if you only wish to move certain groups of blueprint over, you can do so by setting an array of namespaces, such as:\n\n```php\n// config/statamic/eloquent-driver.php\n\n'blueprints' =\u003e [\n    'driver' =\u003e 'eloquent',\n    'model' =\u003e \\Statamic\\Eloquent\\Fields\\BlueprintModel::class,\n    'namespaces' =\u003e ['forms', 'navigation'],\n],\n```\n\nThe above example will set all forms and navigation blueprints to use eloquent, while keeping the rest as files.\n\n## Upgrading\n\nAfter updating to a new version of the Eloquent Driver, please ensure you run `php artisan migrate` to update your database to the latest schema.\n\n## Questions\n\n### Can I store users in the database too?\n\nBy default, Statamic users live in the `users` directory of your project. If you wish to move them to the database, please [follow this guide](https://statamic.dev/tips/storing-users-in-a-database). \n\n### Can I store some collections in the database, while keeping others in flat-files?\n\nThis driver **does not** make it possible to have some collections flat-file driven and others Eloquent driven. If you're looking for that, you may want to checkout the [Runway](https://statamic.com/addons/rad-pack/runway) addon, which is part of The Rad Pack.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstatamic%2Feloquent-driver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstatamic%2Feloquent-driver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstatamic%2Feloquent-driver/lists"}