mercredi 7 juillet 2021

fill datatable with query laravel with relationship

i´m traying to create one datatable and fill it with this query:

$llamadas = DB::table('users')->join('llamada', 'users.id', '=', 'llamada.id_teleoperadora')
                                      ->join('llamada_estado', 'llamada_estado.id', '=', 'llamada.id_estado')
                                      ->select('users.nombre as teleoperadora, llamada_estado.mombre as estado');

but datatable return this message:

DataTables warning: table id=calls - Requested unknown parameter 'users.id' for row 0, column 1. For more information about this error, please see http://datatables.net/tn/4

DataTables warning: table id=calls - Exception Message:

`SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in order clause is ambiguos (SQL: select 'users.nombre' as 'teleoperadora, llamada_estado.nombre' from users inner join llamada on users.id = llamada.id_teleoperadora inner join llamada_estado on llamada_estado on llamada_estado.id = llamada.id_estado order by id asc limit 10 offset 0`)

I don´t know that i´m doing wrong...

My datatable script its:

jQuery(function(){

            oTable = $('#calls').DataTable({
                "language": {
                    "url": "//cdn.datatables.net/plug-ins/1.10.16/i18n/Spanish.json"
                },
                processing: true,
                serverSide: true,
                ajax: "",
                'columnDefs': [{
                    'targets': 0,
                    'searchable': false,
                    'orderable': false,
                    'className': 'dt-body-center',
                    'render': function (data, type, full, meta){
                        return '<input type="checkbox" name="id[]" value="' + $('<div/>').text(data).html() + '">';
                    }
                }],
                'order': [[1, 'asc']],
                columns: [
                    { data: '', name: '' },
                    { data: 'id', name: 'id' },
                    { data: 'nomape', name: 'nomape' },
                    { data: 'direccion', name: 'direccion' },
                    { data: 'provincia', name: 'provincia' },
                    { data: 'cp', name: 'cp' },
                    { data: 'telefono', name: 'telefono' },
                    { data: 'users.nombre', name: 'users.nombre' },
                    { data: 'teleoperadora', name: 'estado' },
                ]
            });

If in my script use users.id return this message:

DataTables warning: table id=calls - Requested unknown parameter 'users.id' for row 0, column 1. For more information about this error, please see http://datatables.net/tn/4

how i can solve this problem?

thanks for read and help.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire