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

How to search on column translatable #199

Open
ikkosatrio opened this issue Sep 9, 2019 · 3 comments
Open

How to search on column translatable #199

ikkosatrio opened this issue Sep 9, 2019 · 3 comments

Comments

@ikkosatrio
Copy link

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

@Eskiell
Copy link

Eskiell commented Oct 30, 2019

I no know.

@timopaul
Copy link

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.

@AlbertoSinigaglia
Copy link

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

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

No branches or pull requests

4 participants