Laravel-datatables: join queries not working with yajra datatable service implementation as expected.

Created on 9 Jun 2018  路  3Comments  路  Source: yajra/laravel-datatables

Summary of problem or feature request

i am using laravel 5.6 and for the service implementation i am using full package "yajra/laravel-datatables": "^1.0"

my problem is generated datatable last result id is repeating for action column, but rest of the columns in getColumns() functions displayed correctly.

any help or tips?. thanks

Code snippet of problem

public function dataTable($query) {
    return datatables($query)
              ->addColumn('action', function($q) {
                     return '<button>' . $q->id . '</button>'
             }
}
public function query(User $model) {
    return $model->newQuery()
               ->join('contacts', function($join) {
                  $join->on('users.id, '=', 'contacts.user_id')->orOn('users.id', '=', 'contacts.proxy_user_id');
               })
               ->select('users.*', 'contacts.*')
}

System details

  • Operating System: ubuntu OS 18
  • PHP Version: php 7.1
  • Laravel Version: laravel 5.6
  • Laravel-Datatables Version: "yajra/laravel-datatables": "^1.0"
question

Most helpful comment

anyway i found out the solution. query method is confusing with many id's while returning two table using asteriask. the better way only return needed column for the join table. hope someone find it useful

All 3 comments

anyway i found out the solution. query method is confusing with many id's while returning two table using asteriask. the better way only return needed column for the join table. hope someone find it useful

Please close the issue if you can, or provide a working solution and mark it solved.
We can all learn from each other here. Thanks!

@maxipy glad you found the solution. It's indeed needed to specifically include which columns to select to avoid confusions on laravel side which id to use.

@cudzich I think this is how he coded his solution:

 ->select('users.id as user_id', 'contacts.id as contact_id', 'users.name', etc..)
Was this page helpful?
0 / 5 - 0 ratings

Related issues

alejandri picture alejandri  路  3Comments

nasirkhan picture nasirkhan  路  3Comments

t0n1zz picture t0n1zz  路  3Comments

FilipeBorges1993 picture FilipeBorges1993  路  3Comments

SGarridoDev picture SGarridoDev  路  3Comments