corcel icon indicating copy to clipboard operation
corcel copied to clipboard

make meta optional

Open Stevemoretz opened this issue 4 years ago • 1 comments

  • Corcel Version: 5
  • Framework Name & Version: php vanilla
  • PHP Version: 7
  • Database Driver & Version: Mysql

Description:

I get

"meta": [
            {
                "meta_id": 1679,
                "post_id": 560,
                "meta_key": "_elementor_edit_mode",
                "meta_value": "builder",
                "value": "builder"
            },

with each post I want to get metas manually not automatically this makes my api slower.

Stevemoretz avatar Dec 27 '20 21:12 Stevemoretz

@jakejohns You should change:


    public function getMeta($attribute)
    {

	    if ($meta = $this->meta->{$attribute}) {
            return $meta;
        }

        return null;
    }

to


    public function getMeta($attribute)
    {
    	
	    if ($meta = $this->meta()->where('meta_key',$attribute)->value('meta_value')) {
            return $meta;
        }

        return null;
    }

Now it doesn't go get all metas it only gets one meta the meta we asked for.

Stevemoretz avatar Dec 29 '20 07:12 Stevemoretz