Skip to content

Issue in the file-handling when using loadCount() on model #19

@rbruhn

Description

@rbruhn

I've ran into a situation where I cannot use loadCount() on a model when the model is using laravel-paperclip.
The error is pasted below and comes from this package.

$project = Project::find(13);
$project->loadCount('expeditions');
dd($project->expeditions_count);

The above results in the following error:

 Could not interpret given data, string value expected

  at vendor/czim/file-handling/src/Storage/File/StorableFileFactory.php:104
    100▕             $data = new RawContent($data);
    101▕         }
    102▕
    103▕         if (! ($data instanceof RawContentInterface)) {
  ➜ 104▕             throw new UnexpectedValueException('Could not interpret given data, string value expected');
    105▕         }
    106▕
    107▕         return $this->interpretFromRawContent($data, $name, $mimeType);
    108▕     }

      +10 vendor frames 

  11  app/Console/Commands/AppCommand.php:56
      Illuminate\Database\Eloquent\Model::loadCount()
      +12 vendor frames 

I have two models, Project and Expedition, that use Laravel-Paperclip. I tried loading counts of other relations that do not use laravel-paperclip and they don't work either. Example:

$project->loadCount('expeditions'); // returns error
$project->loadCount('panoptes'); // returns error
$expedition->loadCount('events'); // returns error

If I use a model that doesn't use Laravel-Paperclip, the loadCount() works as expected.
Edit: Querying withCount() works as expected. I use loadCount() in this situation because it's a route using model binding.

Any idea on how to fix this?

Oh... an example of my Project model... real simple:

public function __construct(array $attributes = [])
{
    $this->hasAttachedFile('logo', [
        'url' => config('config.missing_project_logo'),
    ]);

    parent::__construct($attributes);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions