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

Call to undefined method Illuminate\Database\Eloquent\Builder::id() #226

Closed potsky closed 8 months ago

potsky commented 8 months ago

Hi!

When setting an avatar to user blueprint on a fresh install, an exception is thrown Call to undefined method Illuminate\Database\Eloquent\Builder::id() (View: /var/www/html/vendor/statamic/cms/resources/views/partials/global-header.blade.php)

Step to reproduce:

            handle: avatar
            field:
              mode: grid
              container: images
              folder: avatar
              restrict: true
              allow_uploads: true
              show_filename: true
              show_set_alt: true
              type: assets
              display: Avatar
              icon: assets
              listable: true
              instructions_position: above
              visibility: visible
              replicator_preview: true
              hide_display: false

The method Statamic\Auth\HasAvatar::avatarFieldSquareThumbnailUrl() fails at the first line:

        $assetId = optional($this->avatarFieldValue()->value())->id();

When debugging $this->avatarFieldValue()->value(), I have this:

Statamic\Assets\OrderedQueryBuilder {#2967▶
  #builder: Statamic\Eloquent\Assets\AssetQueryBuilder {#2920▶
    #builder: Illuminate\Database\Eloquent\Builder {#2973▶
      #query: Illuminate\Database\Query\Builder {#2931▶}
      #model: Statamic\Eloquent\Assets\AssetModel {#2937▶}
      #eagerLoad: []
      #localMacros: []
      #onDelete: null
      #propertyPassthru: array:1 [▶]
      #passthru: array:28 [▶]
      #scopes: []
      #removedScopes: []
    }
    #columns: null
    #operators: array:11 [▶]
  }
  #order: array:1 [▶
    0 => "images::["avatar\/rb-512.jpg"]"
  ]
  #ordered: false
  #limit: null
  #offset: null
}

But I am unable to find any method named →id() or magic method __call.

Do you have any ID of what is an →id() on Statamic\Assets\OrderedQueryBuilder ?

ryanmitchell commented 8 months ago

Maybe try adding max_items: 1 to the files configuration.

potsky commented 8 months ago

you rock @ryanmitchell 👍 It works, thank you!