Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How does corcel use order by to sort metadata? #593

Open
evernoever opened this issue Nov 24, 2021 · 1 comment
Open

How does corcel use order by to sort metadata? #593

evernoever opened this issue Nov 24, 2021 · 1 comment

Comments

@evernoever
Copy link

  • 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’ ?

@jgrossi
Copy link
Member

jgrossi commented Nov 25, 2021

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 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants