私はこれを返信して作業していましたが、うまくいきましたが、今度は "hasMany"リレーションを呼び出してテーブルに表示する必要があります これは私のコントローラです:データ型(yajrabox)ネストされたオブジェクトの表示(laravel hasMany relationship)
public function anyData()
{
$posts = Test::with('cola')->select('tests.*');
return \DataTables::eloquent($posts)
->make(true);}
それは私にこの(testanyDataルート)のような配列を与える:
{
"draw": 0,
"recordsTotal": 1,
"recordsFiltered": 1,
"data": [
{
"id": "1",
"nombre": "Sigrid Mann",
"descripcion": "lPcA0",
"stock": "49",
"imagen": "s14gN",
"created_at": "2017-10-27 18:35:54",
"updated_at": "2017-10-27 18:35:54",
"cola": [
{
"test_id": "1",
"tipo": "1",
"precio": "1",
"created_at": null,
"updated_at": null
}
]
}
],
"queries": [
{
"query": "select count(*) as aggregate from (select '1' as `row_count` from `tests`) count_row_table",
"bindings": [],
"time": 0.6
},
{
"query": "select `tests`.* from `tests`",
"bindings": [],
"time": 0.46
},
{
"query": "select * from `precios` where `precios`.`test_id` in (?)",
"bindings": [
1
],
"time": 0.52
}
],
"input": []
}
これは私のjsです:
$(document).ready(function(){
listar();
});
var listar = function(){
var table = $('#productos').DataTable({
"processing": true,
"serverSide": true,
"ajax": "testanyData",
"columns":[
{data:'id'},
{data:'nombre'},
{data:'stock'},
{data: 'cola.precio'},
{defaultContent:
"some buttons"
}
],
"language": idioma_esp
});
}
しかし、私はビューをロードするとき、私はこれでアラートを取得する:
のDataTable警告:テーブルのid = PRODUCTOS - 行0のために要求された未知パラメータ 「cola.precio」、詳細については、列3この エラーは、http://datatables.net/tn/4
を参照してください。これは、ビューの私のテーブルです:
<div class="row-fluid margin-body">
<table id="productos" class="table table-hover table-condensed " >
<thead>
<tr>
<th >Id</th>
<th>Producto</th>
<th>Stock </th>
<th>Precio</th>
<th></th>
</tr>
</thead>
</table>
</div>
私はトンで "PRECIO" を表示させたいです彼はタグ「Precio」をタグ付けします。
これは私が夢中になってくれてありがとう –