corcel / corcel

Use WordPress backend with Laravel or any PHP application

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Trying to get property 'guid' of non-object.

TheRealSageKing opened this issue · comments

  • Corcel Version: 5.1.1
  • Framework Name & Version: Laravel 9.0
  • PHP Version: 7.4
  • Database Driver & Version: MYSQL 8.0

Description:

I get the above error when i try to get featured image of a post with bad featured image.

Steps To Reproduce:

  • Install FakerPress (to generate random posts with featured images)

  • from laravel make a request to fetch all posts and display feature images

  • I used this method in my model to retrieve thumbnails

public function getPostThumbnail()
    {
        try{
            if ( !is_null($this->meta->_thumbnail_id) )
            {
                return $this->thumbnail;
            }
            return asset('images/blog/1.jpg');
        }catch(\Exception $ex)
        {
            return asset('images/blog/1.jpg');
        }
    }

so i can call it like so $post->getPostThumbnail().

I got the error as shown in the screenshot below
Screenshot 2022-03-09 at 02 44 46