singlequote / Laravel-datatables

This repo contains a Datatable that can render a filterable and sortable table. It aims to be very lightweight and easy to use. It has support for retrieving data asynchronously, pagination and recursive searching in relations.
https://singlequote.github.io/Laravel-datatables/
MIT License
18 stars 6 forks source link

Table column with Relation #10

Closed kastoras closed 5 years ago

kastoras commented 5 years ago

Hello,

if i have a model that is related with another model, is there any simple way to show related value at datatable column?

Thanks in advance.

kastoras commented 5 years ago

Finally i have found a solution, it wasn't hard to do.

I used query method and join the related table.

wimurk commented 5 years ago

Hi @kastoras, yes you can use the query like below

public function query($query){
   return $query->with('my-relation');
}

Or you use the auto detect functionality. In your tableModel you can pass relations in the $columns array.

public $columns = [
 'id',
 'my-relation.id' //<== this will be autoloaded
];