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

WithTranslation select specific fields #438

Open
Inpanic97 opened this issue Dec 9, 2024 · 1 comment
Open

WithTranslation select specific fields #438

Inpanic97 opened this issue Dec 9, 2024 · 1 comment

Comments

@Inpanic97
Copy link

Currently, the withTranslation method does not allow selecting specific fields from the translations table while querying the translateable model. For example, I want to retrieve only certain translations (e.g., description) alongside selected fields from the translateable model, but this is not possible in a clean and efficient way.

I would like the ability to query translations more concisely and intuitively, such as:

$model = Model::select('id')->withTranslation(['description'])->get();

This approach would be cleaner and more aligned with Laravel's Eloquent principles, avoiding the need for more verbose solutions like:

$model = Model::with(['translations' => function ($query) {
    $query->where('locale', app()->getLocale())
          ->select('model_id', 'description', 'locale');
}])->get();

The proposed syntax makes the query more readable and reduces boilerplate code.

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

No branches or pull requests

2 participants
@Inpanic97 and others