0

please help me my problem is this:

I'm having relationships in laravel with eloquent. I tried to use Datatables but I don't know how to do "BelongTo Relations". Also, look for an idea in Relationships

I tried "Model Belongs To Demo" but I have no results. It also returns the error:

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

In index.blade.php is the JS
<script>
    $(document).ready(function() {
        $('#certificaciones').DataTable({
            "processing": true,
            "serverSide": true,
            "ajax": "{{ url('api/certification') }}",
            //Nuevo campo de "method"
            "method": "GET",
            "columns": [
                {data: 'date'},
                {data: 'mat_professional_details.n_matriculated', name: 'mat_professional_details.n_matriculated'},
                {data: 'customer'},
                {data: 'n_invoice'},
                {data: 'item'},
                {data: 'mod'},
                {data: 'obs'},
                {data: 'btn'},

            ],
            "language": {
                "info": "_TOTAL_ certificaciones",
                "search": "Buscar",
                "paginate": {
                    "next": "Siguiente",
                    "previous": "Anterior",
                },
                "lengthMenu": 'Mostrar <select>' +
                            '<option value="10">10</option>'+
                            '<option value="25">25</option>'+
                            '<option value="50">50</option>'+
                            '<option value="100">100</option>'+
                            '</select> certificaciones',
                "loadingRecords": "Cargando...",
                "processing": "Procesando...",
                "emptyTable": "No hay datos",
                "zeroRecords": "No hay resultados", 
                "infoEmpty": " ",
                "infoFiltered": " ",
            }
        });
    });
</script>
In RelationCertificationController.php is the "getBelongsTo"
<?php

namespace App\Http\Controllers;

use App\DocCertification;
use App\MatProfessionalDetail;
use Illuminate\Http\Request;

class RelationCertificationController extends Controller
{
    public function getBelongsTo(Request $request)
    {
        if ($request->ajax()) {
            $query = DocCertification::with('mat_professional_details')->select('doc_certifications.*');

            return $this->dataTable->eloquent($query)->make(true);
        }

        return view('vendor/voyager/certification/index');
    }
}
In api.php
Route::get('/certification', function(){
    return datatables()
    ->eloquent(DocCertification::query())
    ->addColumn('btn', 'vendor/voyager/certification/actions')
    ->rawColumns(['btn'])
    ->toJson();
});
In web.php
Route::get('/certification', 'RelationCertificationController@getBelongsTo');
The "doc_certifications" table is the "DocCertification" model and the "mat_matriculated_details" table is the "mat_professional_details" model

The fields of "doc_certifications" are: "id", "date", "n_matriculated", "customer", "n_invoice", "item", "mod", "obs"

The fields for "mat_professional_details" are: "id", "dni", "matriculated_categories", "n_matriculated", "specialty", "email", "title", "date", "university", "obs"

Also "created_at" and "updated_at" in both tables.

System details

  • Operating System
  • PHP: 7.4.3
  • Laravel: 6.5
  • Laravel-Datatables Version: 9.0
Kampai
  • 22,848
  • 21
  • 95
  • 95

0 Answers0