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 72 forks source link

Customizing the shallow augmenation throws an error #189

Closed goellner closed 12 months ago

goellner commented 1 year ago

Customizing the shallow augmenation https://statamic.dev/extending/augmentation#shallow-augmentation doesn't work with the elqouent driver. It throws an error when clearing the cache.

<?php

namespace Domain\Statamic;

use Statamic\Entries\Entry;

class CustomEntry extends Entry
{
    public function shallowAugmentedArrayKeys(): array
    {
        return ['id', 'title', 'url', 'permalink'];
    }
}

I also added

<?php

namespace App\Providers;

use Domain\Statamic\CustomEntry;
use Illuminate\Support\ServiceProvider;
use Statamic\Contracts\Entries\Entry;
use Statamic\Statamic;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     */
    public function register(): void
    {
        //
    }

    /**
     * Bootstrap any application services.
     */
    public function boot(): void
    {
        Statamic::vite('app', [
            'resources/js/cp.js',
            'resources/css/cp.css',
        ]);

        $this->app->bind(
            Entry::class,
            CustomEntry::class
        );
    }
}

to the AppServiceProvider like stated here https://statamic.dev/extending/repositories#custom-data-classes

Here is the error message: https://share.getcloudapp.com/YEu4WWln

ryanmitchell commented 1 year ago

I think the issue is that you should be extending Statamic\Eloquent\Entries\Entry not Statamic\Entries\Entry

goellner commented 12 months ago

Changing it does not throw an error, but also doesn't do anything do the shallowAugmenation. When I override the Entry in the vendor folder it works.

goellner commented 12 months ago

found the issue, had to change the binding in the eloquent-driver.php config file

    'entries' => [
        'driver' => 'eloquent',
        'model' => EntryModel::class,
        'entry' => CustomEntry::class,
    ],