corcel / corcel

Use WordPress backend with Laravel or any PHP application

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How does corcel use order by to sort metadata?

evernoever opened this issue · comments

  • Corcel Version: 5.0
  • Framework Name & Version:Laravel 5.5
  • PHP Version: 7.3
  • Database Driver & Version:MySQL 5.7

Description:

Is there any good way for corcel to sort metadata using ‘order by’ ?

hey @evernoever I'm gonna assume you want to order a metadata from a post. The ->meta is basically an Eloquent's HasMany relationship. When you use $post->meta->foo behind the scenes you're calling $post->meta()->get()->first(...) so you get a collection of "meta" but we return the first one that matches the key.

If you want to order it, then you need to recreate the process, so you can $post->meta()->orderBy()->get()->first(...)

check how meta works in Corcel\Model\Collection\MetaCollection 👍