corcel / corcel

Use WordPress backend with Laravel or any PHP application

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BadMethodCallException Call to undefined method Corcel\Model\Meta\ThumbnailMeta::saveMeta()

interludic opened this issue · comments

  • Corcel Version: "jgrossi/corcel": "^5.0",
  • Framework Name & Version: Laravel 8
  • PHP Version: 8
  • Database Driver & Version: mysql

Description:

How do we add a thumbnail given the path to the file?
image

how to $post->thumbnail->saveMeta([?

Steps To Reproduce:

/**
     * Add a thumbnail to the post
     *
     **/
    public function addThumbnail($post, $path, $prefix = null)
    {
        $fileNameWithDir = date('Y') . '/' . date('m') . '/' . $prefix . basename($path);
        // _thumbnail_id
        if (!empty($post)) {
            $post->saveMeta([
                '_thumbnail_id' => $fileNameWithDir,
                'post_id' => $post->ID,
            ]);

            $post->thumbnail->saveMeta([
                '_wp_attached_file' => $fileNameWithDir,
                '_wp_attachment_metadata' => serialize([
                    "width" => 1656,
                    "height" => 1656,
                    "file" => $fileNameWithDir,
                    "sizes" => [
                        "medium" => [
                            "file" => basename($path), //-300x300
                            "width" => 300,
                            "height" => 300,
                            "mime-type" => mime_content_type($path),
                        ],
                        "large" => [
                            "file" => basename($path), //"-1024x1024.jpg"
                            "width" => 1024,
                            "height" => 1024,
                            "mime-type" => mime_content_type($path),
                        ],
                        "thumbnail" => [
                            "file" => basename($path), //"-150x150.jpg"
                            "width" => 150,
                            "height" => 150,
                            "mime-type" => mime_content_type($path),
                        ],
                        "medium_large" => [
                            "file" => basename($path), //"-768x768.jpg"
                            "width" => 768,
                            "height" => 768,
                            "mime-type" => mime_content_type($path),
                        ],
                    ],
                ]),
            ]);

            dd($post->thumbnail);

            //s:9:"1536x1536";a:4:{s:4:"file";s:30:"wp-1589250785764-1536x1536.jpg";s:5:"width";i:1536;s:6:"height";i:1536;s:9:"mime-type";s:10:"image/jpeg";}}s:10:"image_meta";a:14:{s:8:"aperture";s:3:"1.7";s:6:"credit";s:0:"";s:6:"camera";s:8:"SM-G930F";s:7:"caption";s:0:"";s:17:"created_timestamp";i:1589088719;s:9:"copyright";s:0:"";s:12:"focal_length";s:1:"0";s:3:"iso";s:2:"50";s:13:"shutter_speed";s:6:"0.0019";s:5:"title";s:0:"";s:11:"orientation";s:1:"0";s:8:"keywords";a:0:{}s:11:"ExifVersion";s:4:"0220";s:7:"created";s:25:"2020-05-10T15:31:59+10:00";}}

        }
    }

Related to #542

how do i assign an attachment to a thumbnail?
is it going to be a custom sql insert?

It would be helpfull to return the thumbnail instance (id atleast ) so we can create an attachment for it...