Laravel-datatables: Search feature with laravel-translatable

Created on 13 Jun 2018  路  2Comments  路  Source: yajra/laravel-datatables

I want to search by title. But the title field is another table. I am using this package
https://github.com/dimsav/laravel-translatable

Here are the tables structure :

****** Files *******
id | slug

******** FileTranslation ********
id | file_id | title | description
question

Most helpful comment

Manual search worked for me.

->filter(function ($query) {
               if(request()->has('search') && isset(request()->input('search')['value']) && !empty(request()->input('search')['value'])){
                   $search_term = request()->input('search')['value'];
                   $query->whereTranslationLike('title',  "%". $search_term . "%");
               }
           })

All 2 comments

Manual search worked for me.

->filter(function ($query) {
               if(request()->has('search') && isset(request()->input('search')['value']) && !empty(request()->input('search')['value'])){
                   $search_term = request()->input('search')['value'];
                   $query->whereTranslationLike('title',  "%". $search_term . "%");
               }
           })

Glad you sorted out this one. Thanks for sharing the solution.

Was this page helpful?
0 / 5 - 0 ratings