Skip to content

Conversation

@eslam-dev
Copy link

This PR adds a new Eloquent scope orderByLocale() to the HasTranslations trait.

It allows developers to easily sort query results by translated JSON attributes for a specific locale in a clean and expressive way, without writing raw SQL.

This is especially useful for multi-language applications where ordering by a localized field (like name or title) is a common requirement.

The implementation is database-driver aware and supports MySQL, PostgreSQL, and SQLite out of the box.

Example usage

// Order products by their name in the current locale
Product::orderByLocale('name')->get();

// Order schools by title in Arabic (descending)
School::orderByLocale('title', 'desc', 'ar')->get();

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

Successfully merging this pull request may close these issues.

1 participant