Я не знаю, как реализовать «Принадлежит». Laravel - PullRequest
0 голосов
/ 07 апреля 2020

, пожалуйста, помогите мне, моя проблема заключается в следующем:

У меня есть отношения в laravel с Eloquent. Я пытался использовать Datatables, но я не знаю, как сделать " BelongTo Relations ". Кроме того, ищите идею в Отношения

Я пробовал "Model Belongs To Demo", но у меня нет результатов. Он также возвращает ошибку:

«Предупреждение DataTables: таблица id =tificaciones - Запрошенный неизвестный параметр« 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();
});
В сети. 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
  • Laravel: 6,5
  • Laravel - Версия данных: 9,0
...