0

请帮帮我我的问题是这样的:

我在 laravel 中与 eloquent 有关系。我尝试使用 Datatables 但我不知道如何做“ BelongTo Relations ”。另外,在关系中寻找一个想法

我试过“模型属于演示”,但没有结果。它还返回错误:

“DataTables 警告:表 id=certificaciones - 请求的未知参数 'mat_professional_details.n_matriculated' 用于第 0 行、第 1 列。有关此错误的更多信息,请参阅http://datatables.net/tn/4

在 index.blade.php 是 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>
在 RelationCertificationController.php 中是“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');
    }
}
在 api.php
Route::get('/certification', function(){
    return datatables()
    ->eloquent(DocCertification::query())
    ->addColumn('btn', 'vendor/voyager/certification/actions')
    ->rawColumns(['btn'])
    ->toJson();
});
在 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.

系统详情

  • 操作系统
  • PHP:7.4.3
  • 拉拉维尔:6.5
  • Laravel 数据表版本:9.0
4

0 回答 0