-
-
Notifications
You must be signed in to change notification settings - Fork 157
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
method that includes model attributes with translatable attributes #416
Comments
Hey, sorry but I have no idea what you mean. In case you are after a toArray() like method for APIs: Eloquent API resources will be my one and only all time answer. https://laravel.com/docs/11.x/eloquent-resources I'm in no way interested in adding anything that would promote toArray() usage in any way. |
I made a new scope function public function scopeWithTranslationOnly(Builder $query, string $translationField)
{
$query->with([
'translations' => function (Relation $query) use ($translationField) {
return $query->select($translationField, $this->getTranslationRelationKey())
->where($this->getTranslationsTable().'.'.'language_id', LanguageFacade::getLanguage()->id);
},
]);
} But if you apply $doctorSpecialities = DoctorSpeciality::withTranslationOnly('label')->get(); I get {
"id":1,
"image":"docspec.svg",
"sort_order":23,
"created_at":"2024-06-26T21:19:14.000000Z",
"updated_at":"2024-06-26T21:19:14.000000Z",
"label":null,
"name":null,
"name_plural":null,
"slug":null,
"meta_title":null,
"meta_description":null,
"translations":[
{
"label":"Dudley Schmitt",
"doctor_speciality_id":1
}
]
} data is not filled in label - how to make them fill up ? How are model attributes combined with the attributes of the translated model? |
laravel-translatable/src/Translatable/Translatable.php Lines 140 to 162 in 250f9b3
|
Please tell me a method that includes model attributes with translatable attributes in the package
For example, we write instead of $post->translations->name - $post->name
The text was updated successfully, but these errors were encountered: