statamic / eloquent-driver

Provides support for storing your Statamic data in a database, rather than flat files.
https://statamic.dev/tips/storing-content-in-a-database
MIT License
104 stars 74 forks source link

How to use Eloquent for things other than entries #116

Closed petemolinero closed 1 year ago

petemolinero commented 1 year ago

I just installed a fresh installation of Statamic 3.4 (actually, I tried this first with Statamic 3.3.67, with the same result). Then I did the following commands/tasks from within the Statamic root directory:

  1. composer require statamic/eloquent-driver
  2. php artisan vendor:publish --tag="statamic-eloquent-config"
  3. Delete content/collections/pages/home.md
  4. Change the structure tree in content/collections/pages.yaml to {} ... My copy of content/collections/pages.yaml does not have a tree key. Not sure if I'm supposed to add one with the value of {}, or am supposed to actually be modifying the file in content/trees/collections/pages.yaml. I'm guessing the latter? I've tried both. Maybe ✅
  5. Run php artisan vendor:publish --provider="Statamic\Eloquent\ServiceProvider" --tag=migrations. I got a message saying No publishable resources for tag [migrations]. Publishing complete. Is that normal?
  6. Run php artisan vendor:publish --tag="statamic-eloquent-entries-table"
  7. Run php artisan migrate

At this point, according to the readme, I might be done? It says:

The configuration file (statamic.eloquent-driver) allows you to choose which repositories you want to be driven by eloquent. By default, all are selected, but if you want to opt out simply change driver from eloquent to file for that repository.

Problem is, the entire contents of my config/statamic/eloquent-driver.php file are as follows:

return [

    'entries' => [
        'model' => \Statamic\Eloquent\Entries\EntryModel::class,
    ],

];

I also tried running things like php please eloquent:import-collections, and got an error saying:

❯ php please eloquent:import-collections

Command "eloquent:import-collections" is not defined.

Do you want to run "eloquent:import-entries" instead?  (yes/no) [no]:

I also noticed that there was a migration to add an entries table, but no migrations for any other type of content.

Is this normal and I'm just missing something? How do I get things other than entries to be database-based?

ryanmitchell commented 1 year ago

Sounds like you're getting an older version pulled in by composer - something before 1.1. What PHP version are you running?

petemolinero commented 1 year ago
Composer version 2.3.10 2022-07-13 15:48:23
ryanmitchell commented 1 year ago

Thats your composer version, I need PHP. For context this package is PHP 8+ so if you're below that you'd need to update.

petemolinero commented 1 year ago

Oops, yep, I misread that. My PHP version is 7.4.30, which would explain it. Thanks!

petemolinero commented 1 year ago

Thanks for the quick replies! Should be a simple resolution. Also, what's the technical answer to my Change the structure tree in content/collections/pages.yaml confusion up above?

ryanmitchell commented 1 year ago

Yes its the latter (though I've personally found you dont need this step if everything is running from eloquent).

petemolinero commented 1 year ago

Closing this. I've added a PR to fix that tree filepath typo.

https://github.com/statamic/eloquent-driver/pull/117/files