I want to implement DataTables as a service, so I have followed this tutorial: http://datatables.yajrabox.com/service
I have created a DataTable for my User collection using this command:
php artisan datatables:make UsersDataTable
So, in my app/DataTables/UsersDataTable.php I have configured it as shown:
I am trying to show records from two tables...
<?php
namespace App\DataTables;
use App\User;
use Yajra\Datatables\Services\DataTable;
class UsersDataTable extends DataTable
{
public function ajax()
{
return $this->datatables
->eloquent($this->query())
->addColumn('action', '<button class="btn btn-primary">Edit</button>')
->make(true);
}
public function query()
{
$users = User::query()
->leftJoin('roles', 'roles.id', '=', 'users.role_id')
->select([
'users.id',
'users.name',
'roles.name as role'
]);
return $this->applyScopes($users);
}
public function html()
{
return $this->builder()
->columns($this->getColumns())
->ajax('')
->addAction(['width' => '80px'])
->parameters($this->getBuilderParameters());
}
private function getColumns()
{
return [
'id',
'name',
'role'
];
}
protected function filename()
{
return 'users';
}
}
This results in the following:
As you can see, this works as expected. This page runs on the following Url:
How can I link the Edit button to a link like this:
Where xxx is the id of the row record?
