Skip to content

WithTranslation select specific fields #438

@Inpanic97

Description

@Inpanic97

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions