searchable icon indicating copy to clipboard operation
searchable copied to clipboard

How to search on column translatable

Open ikkosatrio opened this issue 5 years ago • 3 comments

i use this library https://github.com/Astrotomic/laravel-translatable/ how to search on colum translatable?

ikkosatrio avatar Sep 09 '19 15:09 ikkosatrio

I no know.

Eskiell avatar Oct 30 '19 01:10 Eskiell

Does anyone have a solution? I am facing the same problem.

So far my solution is via the join configuration:

    /**
     * Searchable rules.
     *
     * @var array
     */
    protected $searchable = [
        'columns' => [
            'article_translations.title' => 10,
            'article_translations.keywords' => 8,
            'article_translations.description' => 2,
        ],
        'joins' => [
            'article_translations' => [
                'articles.id', 'article_translations.article_id',
            ],
        ],
    ];

But all translations are always returned and so I have each modal n times, where n is the number of possible translations.

timopaul avatar Mar 21 '20 09:03 timopaul

Hi all, I'm using this code:

$prods = Product::whereIn('product_id', function($query) use ($search){
    return $query->fromSub(
        ProductTranslation::search($search, 0)->select('product_id')->distinct(),
        'tmp'
    );
})->get();

where Product is the main model, ProductTranslation is the translation models, and the searchable array looks like this:

protected $searchable = [
    /**
     * Columns and their priority in search results.
     * Columns with higher values are more important.
     * Columns with equal values have equal importance.
     *
     * @var array
     */
    'columns' => [
        'products_translations.product_name' => 10,
        'products_translations.product_description' => 5,
    ],
];

this works, but there is for sure better way to do this

AlbertoSinigaglia avatar Sep 23 '21 17:09 AlbertoSinigaglia