Would there be any way to pass the model relationship to the columns of the Datatable server side?
For example in the Datatable script:
columns: [
{ data: 'marca_id', name: 'marca_id' },
{ data: 'automovel_modelo', name: 'automovel_modelo' },
{ data: 'action', name: 'action', orderable: false, searchable: false}
],
Where tag_id would have to receive the relationship value to display the tag name according to ID.
Function in model with relationship:
public function marca(){
return $this->belongsTo('App\Models\Config\Transito\AutomovelMarca');
}
Controller that displays data:
public function getData ()
{
$automovel_modelo = AutomovelModelo::all();
return Datatables::of($automovel_modelo)
->addColumn('action', function($automovel_modelo){
return
'<a href="automoveis_modelos/'. $automovel_modelo->id .'/edit" class="btn btn-xs btn-warning" title="Editar">
<i class="fa fa-pencil"></i>
</a>' .
'<a onclick="deleteData('. $automovel_modelo->id .')" class="btn btn-danger btn-xs"><i class="glyphicon glyphicon-trash"></i> Delete</a>';
})
->make(true);
return datatables(AutomovelModelo::query())->toJson();
}
But I did not figure out how to move the relationship to json.