Closed ast21 closed 1 year ago
This issue is stale because it has been open 21 days with no activity. Remove stale label or comment or this will be closed in 7 days
hello, any updates and answers?
Hi, I found your question because I had a similar issue. To avoid loading unnecessary columns, you can add disableAutoloadTranslations() to the constructor of your model:
public function __construct()
{
parent::__construct();
self::disableAutoloadTranslations();
}
If you want to disable autoload globally, you can change this translatable.php setting to false:
'to_array_always_loads_translations' => false,
Refer to: https://docs.astrotomic.info/laravel-translatable/package/methods#translation-autoloading
Hi @omarcinkonis .
Thanks for your reply. Now I use that code:
Article::query()
->with('translations', function ($query) {
$query
->select(['article_id', 'locale', 'title']) // without 'content' because it's too big
->where('locale', app()->getLocale());
})
->paginate();
After that, I wrap it in ArticleResource, there I already bring it to the form I need.
Good afternoon!
I have a table of
articles
andarticle_translations
.article_translations
contains two translatable columnstitle
andcontent
. Thecontent
column can contain more than 10,000 characters. To get all thearticles
I do this:and this code get all translated columns, including
content
, but thecontent
column is not needed, and loads the requestHow do I get only the
title
column, excluding thecontent
column?