我尝试使用Chumper datatables library
Laravel 4.2
中的https://github.com/Chumper/Datatable
在页面上显示表格。
我确实加入了我的branch_users
表和users
表,一切正常。见如下。
$branchs = DB::table('branch_users')
->join('users', 'branch_users.employee_id', '=', 'users.employee_id')
->select('branch_users.branch_code as branch_code',
'branch_users.branch_name as branch_name',
'branch_users.employee_id as employee_id',
'users.firstname_th as firstname', 'users.lastname_th as lastname')->get();
当我print_r($branchs)
我得到这样的东西时
Array ( [0] => stdClass Object ( [branch_code] => 333 [branch_name] => Robinson
[employee_id] => 1000169 [firstname] => John [lastname] => Doson )...
问题出在我创建表后我遇到了Ajax错误。
你知道怎么修理它们吗?对不起我的英语不好。提前谢谢。
控制器:
return Datatable::query($branchs)
->showColumns('branch_code', 'branch_name', 'employee_id', 'firstname', 'lastname')
->searchColumns('branch_code', 'branch_name', 'employee_id', 'firstname', 'lastname')
->orderColumns('branch_code', 'branch_name', 'employee_id', 'firstname', 'lastname')
->addColumn('Edit', function($model) {
return '<a href=branchs/'.$model->id.'/edit class="btn btn-info">Edit</a>';
})
->addColumn('Delete', function($model) {
return
Form::open(array('method'=> 'DELETE', 'route' => array('branchs.destroy', $model->id))).
Form::submit('Delete', array('class'=> 'btn btn-danger')).
Form::close();
})
->make();
查看:
{{ Datatable::table()
->addColumn('Branch Code','Branch Name', 'Employee ID','First Name','Last Name','Edit','Delete')
->setUrl(route('api.branchs'))
->render() }}
答案 0 :(得分:0)
soydeMéxico,creo que te sobra el - &gt; get()soloquítalo Tuconsultaquedaríaasí:
$branchs = DB::table('branch_users')
->join('users', 'branch_users.employee_id', '=', 'users.employee_id')
->select(array('branch_users.branch_code as branch_code',
'branch_users.branch_name as branch_name',
'branch_users.employee_id as employee_id',
'users.firstname_th as firstname', 'users.lastname_th as lastname'));