Sto lavorando con i dati Laravel 5.1 + (http://datatables.yajrabox.com/).come modificare la colonna su laravel?
Ho bisogno di modificare la colonna user_id e mostrare il nome e il cognome dalle relazioni.
C'è il mio codice.
public function getOrders(Request $request){
if($request->ajax()) {
$orders = Order::with('call', 'contact.company', 'campaign')
->Client()->Finished()->get();
return Datatables::of($orders)->editColumn('user_id',
function ($orders) {
return $orders->User->firstname.' '.$orders->User->lastname;
})->make(true);
}
return view('global/orders');
}
E c'è la mia datatables.js chiamano:
var oTable = $('#orders-data').dataTable({
"processing": true,
"serverSide": true,
"ajax": '/history/orders',
"columns": [
{ data: 'created_at', name: 'created_at' },
{ data: 'user_id', name: 'user_id' },
{ data: 'call.phone', name: 'phone' },
{ data: 'contact.first_name', name: 'first_name' },
{ data: 'contact.last_name', name: 'last_name' },
{ data: 'contact.company.name', name: 'company' },
{ data: 'contact.address', name: 'address' },
{ data: 'contact.postal', name: 'postal' },
{ data: 'contact.city', name: 'city' },
{ data: 'contact.country', name: 'country' },
{ data: 'campaign.name', name: 'name' },
{ data: 'call.call_length', name: 'call_length' },
{ data: 'call.comment', name: 'comment' },
{ data: 'call.status', name: 'status' },
{ data: 'call.full_record', name: 'full_record' },
{ data: 'action', name: 'action', orderable: false, searchable: false }
]
});
Ma su questo $orders->User->firstname
ho avuto 10 query
select * from `users` where `users`.`id` = 'x' limit 1
Come modificare le colonne con i rapporti sulla $orders = Order::with('user', 'call', 'contact.company', 'campaign')->Client()->Finished()->get();
?